[英]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.