mardi 26 janvier 2016

Update Database On Button Press Not CheckBox Check

I seem to be stuck with tunnel vision only seeing how to update a database based off the check/uncheck event of a checkbox. What I am wanting to do is hold the event from firing until a button is pressed. How could I achieve such?

HTML

<td valign="top" style="text-align: left; width: 200px;">
<asp:GridView runat="server" ID="datagridTest" AutoGenerateColumns="false" GridLines="Both" >
    <Columns>
    <asp:BoundField DataField="thirteen" HeaderText="You" />
    <asp:BoundField DataField="seven" HeaderText="Me" />
    <asp:TemplateField>
        <ItemTemplate>
            <asp:Label runat="server" Text='<%#Eval("josemen1212") %>' ID="red" Visible="false"></asp:Label>
         </ItemTemplate>
        <ItemTemplate>
            <asp:CheckBox ID="checker" runat="server" AutoPostBack="true" OnCheckedChanged="Checker_Click" Checked='<%# Convert.ToBoolean(Eval("green")) %>' />
        </ItemTemplate>
    </asp:TemplateField>
    </Columns>
</asp:GridView>
</br>
<asp:Button runat="server" ID="btnClickMe" CssClass="Buttons" Text="Click" OnClick="btnClickMe_Click" />
</td>

C#

private void btnClickMe_Click(object sender, EventArgs e)
{
  //Here is where I want the update to run
}

protected void Checker_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in dgRD.Rows)
{
    if (row.RowType == DataControlRowType.DataRow)
    {
        CheckBox chk = (CheckBox)row.FindControl("checker");
        if (chk.Checked)
        {
            string ID = ((Label)row.FindControl("josemen1212")).Text;
            //Run Sql statement to update db
        }
        else
        {
            string ID = ((Label)row.FindControl("josemen1212")).Text;
            //Run sql statement to update db
        }
    }
}
}




Aucun commentaire:

Enregistrer un commentaire