当数据绑定模板字段(复选框)的值更改时执行更新语句
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
您必须使用 CheckedChanged 事件....
我有一个模板字段,它是这样数据绑定的:
<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
您必须使用 CheckedChanged 事件....