Accessing CheckBox when canceling edit

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
 
T

tshad

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top