简体   繁体   中英

Do an update statement when Value of a databound Templatefield(checkbox) is changed

I have a template field which is databound like this :

                       <asp:TemplateField HeaderText="NewLine">
                        <HeaderStyle CssClass="TDAll" />
                        <ItemStyle BorderStyle="Solid" HorizontalAlign="Center" CssClass="TDAll" />
                        <ItemTemplate>                                
                            <asp:CheckBox ID="chkNewLine" runat="server" AutoPostBack="True" Checked='<%# Bind("NewLine") %>' CommandArgument='<%# Eval("QuestionPartNumber") %>'/>
                        </ItemTemplate>
                    </asp:TemplateField>

Whenever the checkbox is checked or unchecked I want to write an update statement in codebehind.

Could anyone suggest in which event I can write this update statement keeping in mind that i need the datakey value while writing the update query

My update statemnt will look something like this

        For Each row As GridViewRow In DGSubQuestions.Rows
        Dim cb As CheckBox = row.FindControl("NewLine")
        QuestPartID = DGSubQuestions.DataKeys(e.CommandArgument).Value

        SQLHelper.NonQuery("UPDATE [GPsSubQuestions] SET [NewLine] =" & cb.Checked & " WHERE QuestPartID = @QuestPartID", _
        New SqlParameter("@QuestPartID", QuestPartID))

    Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM