My apologies for a long thread.
I am very amazed for this code
please markup,
& lt; Asp: TemplateField HeaderText = "Action" & gt; & Lt; ItemTemplate & gt; & Lt; ASP: Button ID = "Cancel BTN" style = "width: 105px; padding: 5px; margin: 5px;" Runat = "server" CommandName = "delete" OnDataBinding = "btnDelete_DataBinding" OnClientClick = 'Confirm Return ("Are you sure you want to delete this entry?");' Text = "cancel training" /> Then I have getDateDifference () < / code> Bulayn as the code below: as dim username as private function GetDateDifference () Boolean = session ( "username") dim myConnectionString [string] = ConfigurationManager.ConnectionStrings ( "DBConnectionString"). ConnectionString dim myConnection as New SqlConnection (myConnectionString) myConnection.Open () select as dim cmd1 New SqlCommand ( "DateDiff (dd, GetDate (), d.trainingDates) DaysCountJoin tblCourses at "& amp; _" tblTrainings in T Inner t.courseId = c.courseId and join t.locationId = l.LocationId "& amp; tblLocationsL on Inner; _ "Inner tblTrainingDates Join t.Dateid = d.dateid on" & amp; _ "inner c.courseId = ic.CourseId include tblCourseInstructor IC" & amp; _ "include inner tblInstructors I at ic.instructorId = I.instructorId "& amp; _ "Inner tblLogin LG t.username = lg.username where lg.username = @ Join the username", myConnection) as dim DR1 cmd1.Parameters.AddWithValue ( "@ username" username) SqlDataReader = cmd1.ExecuteReader () if dr1.Read () then dim DaysCount integer = DR1 ( "DaysCount") Response.Write (DaysCount) as DaysCount are & gt, = 2 Otherwise eliminating false finally come true return return False End Function The function is brought down:
Protected sub GridView1_RowDataBound (ByVal As the object, ByVal As GridViewRowEventArgs) if e. Row.RowType = DataControlRowType.DataRow button as btn dim = DirectCast (e.Row.FindControl ( "cancelBtn"), button) btn.Enabled = not getDateDifference () End If End Sub We are all trying to compare trainingdates with the current date.
If the current date is within 24 hours (or 2 days) of the date of training, a user who has already signed up for a class, can not cancel the class.
If the current date is more than 2 days from the date of training, then the user can cancel.
To test, I have 2 training in my account.
> The date of a training is 6/22/2013
Other trials
This is right because today's date 6/21/13 to 6/22 There is one day left for 8 days before the second training date of 2013/2013 and 6/29/2013 second training date.
This means that on my app (please see screenshot), I hope that one button will be disabled and the other capable will be enabled. ! [Enter image details here] [1] As you can see from the screenshot, it is not happening
When I try to debug DayCount with feedback. Write (day count), it shows 11 . > Definitely how is this happening
DB is SQL Server 2005. However production is DB 2008.
Thank you in advance for your help.
I'm not sure what's going on here but to try and debug it, I just return
DateDiff , and then to validate it: dr1.Read () again as dim trngDate date = DR1 ( "trainingDates") Response.Write (trngDate.ToString) if (trngDate - DateTime.Now) .TotalDays & gt; = 2, then it is true or else return false end end if If Return Edit But - why the dates Rodadetound event Do not
There is no need to take any other query, on which date you are comparing it to the line which you binding
something (Anchestr) code: < / p>
protected sub GridView1_RowDataBound (ByVal as this object, ByVal e GridViewRowEventArgs as) if e.Row.RowType = DataControlRowType.DataRow then dim DATEVALUE date = Date.Parse (Convert.ToString ( DataBinderkEval (as EkRowkDataItem, "dates"))) Cancel dim Bitian aS button = Direct Sist (Ikrokfndkantrol ( "Bitian"), button) BTN Encode = (Date Value - Datetime. Now). Toddates & gt; = 2 end if end all
No comments:
Post a Comment