zackeyboyz3
New Member
I am having issue when updating gridview! everything is seems to be working. but when i hit finish editing the data will not save!but when i click edit the correct fields prompt me to enter new value but it wont save!here is my asp\[code\]<asp:GridView ID="GridView1" runat="server" CssClass="report" AutoGenerateColumns="False" onrowediting="GridView1_RowEditing" DataKeyNames="TimeID" onrowupdating="GridView1_RowUpdating" onrowcommand="GridView1_RowCommand" onrowcancelingedit="GridView1_RowCancelingEdit"> <Columns> <asp:BoundField DataField="date" Visible="true" ReadOnly="true" HeaderText="Date" /> <asp:BoundField DataField="Description" HeaderText="Stage Description" ReadOnly="True" /> <asp:TemplateField HeaderText="Start Time"> <ItemTemplate> <asp:Label ID="Label7" runat="server" Text='<%# ConvertToShotTime(Eval("StartTime")) %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtStartTime" ValidationGroup="1" Width="90px" class="TimeEntry" runat="server" Text='<%# ConvertToShotTime(Eval("StartTime")) %>'></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="txtStartTime" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="End Time"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# ConvertToShotTime(Eval("EndTime")) %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtEndTime" class="TimeEntry" ValidationGroup="1" Width="90px" runat="server" Text='<%# ConvertToShotTime(Eval("EndTime")) %>'></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator66" ControlToValidate="txtEndTime" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator> </EditItemTemplate> </asp:TemplateField> <asp:BoundField DataField="TimeInHours" HeaderText="Time Time (Hours)" ReadOnly="True" /> <asp:CommandField ShowEditButton="true" ShowCancelButton="true" ButtonType="Image" EditImageUrl="~/images/edit_record.jpg" CancelImageUrl="~/images/edit_no.jpg" UpdateImageUrl="~/images/update_record.jpg" /> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:ImageButton ID="lnbCopy" runat="server" AlternateText="Delete" CommandName="DeleteRecord" CommandArgument='<%# Bind("TimeID") %>' OnClientClick="return confirm('Are you sure you want to delete this row?');" ImageUrl="~/images/delete_record.jpg" /> </ItemTemplate> <EditItemTemplate> <asp:Label ID="lblTimeID" runat="server" Text='<%# Eval("TimeID") %>'></asp:Label> </EditItemTemplate> </asp:TemplateField> </Columns></asp:GridView>\[/code\]here is what i have done in behind code\[code\]protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; loadTable();}protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; loadTable();}protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView1.Rows[e.RowIndex] as GridViewRow; var StartTime = row.FindControl("txtStartTime") as TextBox; var EndTime = row.FindControl("txtEndTime") as TextBox; var id = row.FindControl("lblTimeID") as Label; SqlConnection conn = new SqlConnection(conStr.GetConnectionString("myServer1")); SqlCommand comm = new SqlCommand(); comm.CommandText = "UPDATE CDSTimeSheet SET StartTime = @StartTime, EndTime = @EndTime ,timeElapsed = datediff(minute,@startTime , @EndTime), timeInSeconds = datediff(second,@startTime , @EndTime) WHERE TimeID = @id"; comm.Connection = conn; comm.Parameters.AddWithValue("@id", id.Text); comm.Parameters.AddWithValue("@StartTime", StartTime.Text); comm.Parameters.AddWithValue("@EndTime", EndTime.Text); conn.Open(); comm.ExecuteNonQuery(); conn.Close(); GridView1.EditIndex = -1; loadTable();}\[/code\]what am i doing wrong?