Accessing CheckBox when canceling edit

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I am trying to find a way to access a checkbox after the Cancel button is
pressed during inline editing of a GridView.

<asp:TemplateField HeaderText="Reviewed"
ItemStyle-CssClass="alignCenter" SortExpression="Reviewed" Visible="True">
<ItemTemplate >
<asp:CheckBox ID="chkReviewed" runat="server"
OnCheckedChanged="chkReviewed_CheckChanged"
AutoPostBack="True"/></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblReviewed" runat="server" Text='<%# Eval("Reviewed")
== DBNull.Value ? "No" : Convert.ToBoolean(Eval("Reviewed")) ? "Yes" : "No"
%>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>

The problem is that if the chkReviewed is not checked, it will not be
checked if the user pressed the Canel button after editing the line.

I need to set the checkBox regardless of whether the user pressed the Update
or the Cancel button.

I tried the onCancelingEdit event, but it only allows me access to the
objects that were on the row during editing. In this case, that would be
the lblReviewed object and not the chkReviewed object.

Is there a way to know which row was edited during cancellation that would
give me access to the chkReviewed button before it is displayed so I can
check it?

Thanks,

Tom
 
I tried to make the change in onRowEditing which still shows me the
checkBox.

public void GridView1_RowEditing(object sender, GridViewEditEventArgs
e)
{
SqlDataReader dbReader = null;
SqlParameter retValue;
CheckBox checkBox;

GridViewRow gvr = (GridViewRow)GridView1.Rows[e.NewEditIndex];
checkBox = (CheckBox)gvr.FindControl("chkReviewed");
checkBox.Checked = true;

But it must not actually save it at this point, since when I go back (after
hitting Cancel) it is still unchecked.

Tom
 
Back
Top