[英]Do an update statement when Value of a databound Templatefield(checkbox) is changed
I have a template field which is databound like this : 我有一个像这样的数据绑定的模板字段:
<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>
Whenever the checkbox is checked or unchecked I want to write an update statement in codebehind. 每当复选框处于选中状态或未选中状态时,我都想在代码隐藏中编写一条更新语句。
Could anyone suggest in which event I can write this update statement keeping in mind that i need the datakey value while writing the update query 任何人都可以建议在哪种情况下可以编写此更新语句,但要记住在编写更新查询时需要数据键值
My update statemnt will look something like this 我的更新状态看起来像这样
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
You have to use CheckedChanged Event .... 您必须使用CheckedChanged事件...。
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.checkedchanged%28v=vs.110%29.aspx https://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.checkbox.checkedchanged%28v=vs.110%29.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.