【发布时间】: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