I have found this question a few places but no solutions...
I have a checkbox in a gridview:
<asp:TemplateField HeaderText="Closed?">
<ItemTemplate >
<asp:CheckBox ID="Status_CB" runat="server" AutoPostBack="true"
OnCheckedChanged="Status_CB_CheckedChanged"
EnableViewState="true" ViewStateMode="Enabled"
Checked='<%# Convert.ToString(Eval("cStatus")) == "1" ? true : false %>'/>
</ItemTemplate>
</asp:TemplateField>
codebehind:
protected void Page_Load(object sender, EventArgs e) {
if (!int.TryParse(Session["FacilityID"].ToString(), out FId)) {
FId = 0;
}
if (!Page.IsPostBack) {
if (!string.IsNullOrEmpty(Request.QueryString.Get("WorkCenter"))) {
wc = Request.QueryString.Get("WorkCenter");
WorkcenterHeader.InnerText = wc + " Schedule ";
HiddenWorkCenter.Value = c;
}
if (!SQLHasData()) {
SavePrioritiesToSQL();
}
BindGrid();
}
}
protected void Status_CB_CheckedChanged(object sender, EventArgs e) {
CheckBox cb = (CheckBox)sender;
GridViewRow row = (GridViewRow) cb.Parent.Parent;
}
When i check the box originally, it works. When i uncheck it, the breakpoint i have on the first line of Status_CB_CheckedChanged does not fire at all.
What am i missing any one know?
UPDATE - here is the table, it is nested. i wonder if that is the reason it will not call the postback on uncheck...
UPDATE - ok i gave up, this must be a bug with nested gridview in asp so if you have a nested gridview, i recommend not using checkboxes. I switched mine to a text field of the cStatus "open" or "closed" and use a button with a command argument that is the row index:
<asp:GridView ID="JobInfo_GV" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid2" OnRowCommand="JobInfo_GV_RowCommand">
<asp:BoundField DataField="cStatus" HeaderText="Status" ReadOnly="True" HeaderStyle-CssClass="center-row" ItemStyle-CssClass="center-row"/>
<asp:TemplateField HeaderText="Update">
<ItemTemplate >
<asp:Button id="UpdateClosed" commandname="Select" buttontype="button" Text="ToggleStatus" runat="server" CommandArgument='<%# Container.DataItemIndex %>'/>
</ItemTemplate>
</asp:TemplateField>
then the C#:
protected void JobInfo_GV_RowCommand(object sender, GridViewCommandEventArgs e) {
var grid = (GridView)sender;
var errorMessage = string.Empty;
if (grid != null) {
int index = 0;
if (int.TryParse(e.CommandArgument.ToString(), out index) ){
GridViewRow row = grid.Rows[index];