i have a gridview for which i use a textbox in edit item template for editing time.Below is aspx code.
<asp:TemplateField HeaderText="EndTime">
<ItemTemplate>
<asp:Label ID="lblendtime" runat="server" Text='<%# Bind("Endtime","{0:u}") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtendtime123" runat="server" Text= '<%# Bind("Endtime","{0:u}") %>' ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
I have to calculate number of hours based on calculations end time- start time which works fine but the problem is my date automatically gets incremented even when i dont edit it.
Below is the scenario for same.
Example.
my textbox contains::2013-15-08 23:30:00zz
After editing::2013-15-08 23:56:00zz
After Update::2013-16-08 9:40:00zz
below is my C# code for the same.
TextBox txtdatetimeend = (TextBox)gvr.FindControl("txtendtime123");
string endtime = txtdatetimeend.Text;
string[] arrendtime = endtime.Split(' ');
string timepart = arrendtime[1];
string[] splitendtime = timepart.Split(':');
int endhours = Convert.ToInt32(splitendtime[0]);
int endminutes = Convert.ToInt32(splitendtime[1]);
Label lblstarttime = (Label)gvr.FindControl("lblstarttime");
string starttime = lblstarttime.Text;
string[] arrstarttime = starttime.Split(' ');
string startpart = arrstarttime[1];
string[] splitstart = startpart.Split(':');
int starthours = Convert.ToInt32(splitstart[0]);
int startmin = Convert.ToInt32(splitstart[1]);
double finalhours =Convert.ToDouble(endhours - starthours);
int finalminutes = endminutes - startmin;
double newfinalm = Convert.ToDouble(finalminutes);
double newfinalminutes = newfinalm / 60;
double finalentryhours = finalhours + Convert.ToDouble(newfinalminutes);
DateTime dtfrthus = Convert.ToDateTime(endtime);
string dtentertime = Convert.ToString(dtfrthus);
DateTime final = Convert.ToDateTime(dtentertime);
string querystring = Request.QueryString["Userid"];
connfordata.Open();
SqlCommand cmdfrmonday = new SqlCommand("update s001_Timesheets set s001_hrsday4 = '" + finalentryhours + "',s001_TimeEntryEnd = '" + final + "',s001_tsnarrationtxt = '" + narra + "' where s001_TimesheetsID = '" + id + "' ", connfordata);
cmdfrmonday.ExecuteNonQuery();
connfordata.Close();