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 ....