【问题标题】:Do an update statement when Value of a databound Templatefield(checkbox) is changed当数据绑定模板字段(复选框)的值更改时执行更新语句
【发布时间】:2018-01-23 01:38:10
【问题描述】:

我有一个像这样数据绑定的模板字段:

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

每当检查复选框或未选中复选框时,我都想在CodeBehind中编写更新语句。

任何人都可以建议在哪种情况下我可以编写此更新语句,记住我在编写更新查询时需要 datakey 值

我的更新语句看起来像这样

        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

【问题讨论】:

    标签: c# asp.net vb.net code-behind aspxgridview


    【解决方案1】:

    【讨论】:

    • 谢谢Sandeep。但是当我再次加载页面时它不会被触发?
    • 我不明白..你在说什么?你能解释一下吗?
    • sory..我的意思是当我试图调试它的功能时,当复选框被选中或第二次时它没有进入功能。
    • 但是我已经解决了。感谢您的快速回复。
    • 欢迎您 :) @LintaSheelkumar
    猜你喜欢
    • 1970-01-01
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    相关资源
    最近更新 更多