vendredi 22 janvier 2016

Update Database From Grid View Checkbox

I have a grid view on a webform that has a hidden field holding the id, how do I capture the data from the id field to use in my update statement? This is what my syntax looks like...
HTML

    <asp:GridView runat="server" ID="gridview2" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="weekofyear" HeaderText="Week" />
<asp:BoundField DataField="supportname" HeaderText="Name" />
<asp:BoundField DataField="supid" HeaderText="SupportIDName" Visible="false"/>
<asp:TemplateField>
    <ItemTemplate>
        <asp:CheckBox ID="TicketCompleted" runat="server" AutoPostBack="true" OnCheckedChanged="TicketCompletedCompleted_Click" Checked='<%# Convert.ToBoolean(Eval("TicketCompleted")) %>' />
    </ItemTemplate>
</asp:TemplateField>
</Columns>

C#

protected void TicketCompleted_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in dgRD.Rows)
{
    if (row.RowType == DataControlRowType.DataRow)
    {
        //Below captures the checkbox value (yes or no)
        CheckBox chk = (CheckBox)row.FindControl("TicketCompleted");                    
        if (chk.Checked)
        {
            //Here is where I will run the update
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire