Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Checkbox autopostback question

Checkbox autopostback question

Checkbox autopostback question

I have this in my aspx


<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}") %>' />
    <EditItemTemplate >
        <asp:Checkbox ID="DateAnalyzed" runat="server" Text='<%# Eval("Date Analyzed", "{0:d}")%>' AutoPostBack="true" OnCheckedChanged="chkSelect_CheckedChanged" />

and then this in my code behind


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);
                int updated = updateCommand.ExecuteNonQuery();

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.


RE: Checkbox autopostback question

Try putting EnableViewState = false on DateAnalyzed

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close