簡體   English   中英

更改數據綁定Templatefield(復選框)的值時,執行更新語句

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

我有一個像這樣的數據綁定的模板字段:

                       <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>

每當復選框處於選中狀態或未選中狀態時,我都想在代碼隱藏中編寫一條更新語句。

任何人都可以建議在哪種情況下可以編寫此更新語句,但要記住在編寫更新查詢時需要數據鍵值

我的更新狀態看起來像這樣

        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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM