我有一个像这样数据绑定的模板字段:
<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
答案 0 :(得分:0)