Accessing CheckBox when canceling edit

Discussion in 'ASP .Net' started by tshad, Sep 29, 2009.

  1. tshad

    tshad Guest

    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
     
    tshad, Sep 29, 2009
    #1
    1. Advertising

  2. tshad

    tshad Guest

    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

    "tshad" <> wrote in message
    news:...
    >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
    >
    >
    >
     
    tshad, Sep 29, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AT

    Canceling Page.Load event

    AT, Aug 18, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    415
    Rick Strahl [MVP]
    Aug 19, 2005
  2. DazedAndConfused

    Canceling Subsequent events from page_load

    DazedAndConfused, Sep 22, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    539
    DazedAndConfused
    Sep 23, 2005
  3. Replies:
    0
    Views:
    397
  4. Tony
    Replies:
    7
    Views:
    349
  5. perseus
    Replies:
    0
    Views:
    336
    perseus
    Aug 12, 2003
Loading...

Share This Page