ASP.NET with gridview resets all date fields to null when editing (using SQL Server 2012, c#, VS 2017)
I have looked at the one post regarding this, but the answer does not resolve the problem.
Code Snippet below:
aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
DropDownList DropDownList6 = (DropDownList)GridView1.Rows[GridView1.EditIndex].Cells[2].FindControl("DropDownList6");
DropDownList DropDownList5 = (DropDownList)GridView1.Rows[GridView1.EditIndex].Cells[3].FindControl("DropDownList5");
DropDownList DropDownList3 = (DropDownList)GridView1.Rows[GridView1.EditIndex].Cells[4].FindControl("DropDownList3");
TextBox TextBox4 = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[5].FindControl("TextBox4");
TextBox TextBox7 = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[6].FindControl("TextBox7");
TextBox TextBox8 = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[7].FindControl("TextBox8");
TextBox TextBox9 = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[8].FindControl("TextBox9");
TextBox TextBox10 = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[9].FindControl("TextBox10");
TextBox TextBox2 = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[10].FindControl("TextBox2");
SqlDataMaintenanceTasks.UpdateParameters["Location"].DefaultValue = DropDownList6.SelectedValue;
SqlDataMaintenanceTasks.UpdateParameters["Phase"].DefaultValue = DropDownList5.SelectedValue;
SqlDataMaintenanceTasks.UpdateParameters["Periodicity"].DefaultValue = DropDownList3.SelectedValue;
SqlDataMaintenanceTasks.UpdateParameters["Task"].DefaultValue = TextBox4.Text;
SqlDataMaintenanceTasks.UpdateParameters["Team"].DefaultValue = txtTeam.SelectedValue;
SqlDataMaintenanceTasks.UpdateParameters["TimeEstimation"].DefaultValue = TextBox7.Text;
SqlDataMaintenanceTasks.UpdateParameters["ScheduledDate"].DefaultValue = TextBox8.Text;
SqlDataMaintenanceTasks.UpdateParameters["DueDate"].DefaultValue = TextBox9.Text;
SqlDataMaintenanceTasks.UpdateParameters["CompletionDate"].DefaultValue = TextBox10.Text;
SqlDataMaintenanceTasks.UpdateParameters["Comments"].DefaultValue = TextBox2.Text;
SqlDataMaintenanceTasks.Update();
}
.aspx code:
<asp:TemplateField HeaderText="ScheduledDate" SortExpression="ScheduledDate">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("ScheduledDate") %>' TextMode="Date"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtSchedDate" runat="server" TextMode="Date"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("ScheduledDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DueDate" SortExpression="DueDate">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("DueDate") %>' TextMode="Date"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtDueDate" runat="server" TextMode="Date"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("DueDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CompletionDate" SortExpression="CompletionDate">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("CompletionDate") %>' TextMode="Date"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtCompDate" runat="server" TextMode="Date"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("CompletionDate") %>' TextMode="Date"></asp:Label>
</ItemTemplate>
</asp:TemplateField>