I have this in my aspx
and then this in my code behind
which all works, however... The point of this code is to enter today's date when the checkbox is checked, which it does. The caveat is that when it re-binds the gridview it shows both the checkbox AND the date that was just entered. Is there any nice way to, once the box has been checked, not have the checkbox show up any more? So, before it is checked the value is null, but I am not sure how I can use that in this situation.
Thanks,
Willie
Code:
<asp:TemplateField HeaderText="Date Analyzed" SortExpression="Date Analyzed" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
<ItemTemplate >
<asp:Label ID="lblDateAnalyzed" runat="server" Text='<%# Eval("Date Analyzed", "{0:d}") %>' />
</ItemTemplate>
<EditItemTemplate >
<asp:Checkbox ID="DateAnalyzed" runat="server" Text='<%# Eval("Date Analyzed", "{0:d}")%>' AutoPostBack="true" OnCheckedChanged="chkSelect_CheckedChanged" />
</EditItemTemplate>
</asp:TemplateField>
and then this in my code behind
Code:
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
GridViewRow row = (GridViewRow)chk.NamingContainer;
HiddenField hiddenID = (HiddenField)row.FindControl("ID");
string sql = "UPDATE CreditReports.dbo.Customers SET [Date Analyzed]=convert(date, getdate()) WHERE ID=@ID";
string connStrII = ConfigurationManager.ConnectionStrings["visa"].ConnectionString;
using (var con = new SqlConnection(connStrII))
using (var updateCommand = new SqlCommand(sql, con))
{
updateCommand.Parameters.AddWithValue("@ID", int.Parse(hiddenID.Value));
updateCommand.Parameters.AddWithValue("@Status", chk.Checked);
con.Open();
int updated = updateCommand.ExecuteNonQuery();
}
this.BindGridView();
}
which all works, however... The point of this code is to enter today's date when the checkbox is checked, which it does. The caveat is that when it re-binds the gridview it shows both the checkbox AND the date that was just entered. Is there any nice way to, once the box has been checked, not have the checkbox show up any more? So, before it is checked the value is null, but I am not sure how I can use that in this situation.
Thanks,
Willie