Home All Groups Group Topic Archive Search About

How to determine the "state" of a GridView

Author
22 Dec 2005 3:49 AM
Roberto Kohler
How can I tell if the grid is showing me the "edit command button" or the
"update command button"
I need to figure out a way for an event handler to know the "state" of a
gridview.
I want the ENTER key to do one thing if I am in "edit mode", and another
thing if I am in "update mode".

If I am editing a row in a gridView, then the ENTER key should fire the
onclick event for the "update command button" of "the row I am editing".
If I am not editing a row, then the ENTER key should fire the onclick event
for a submit button I have somewhere else on that form.

Author
22 Dec 2005 6:55 AM
Phillip Williams
Hi Roberto,

There is no state for the entire GridView.  Each row can display the
appropriate template based on the chosen row action (in this case
ItemTemplate and EditItemTemplate).

To have the entire page submitted you have to handle the OnKeyPress on the
body object tag level.  For a demo on how to do this you might refer to this
sample: http://www.societopia.net/samples/ASPPage_Buttons.aspx

To cause a textbox within an EditItemTemplate to cause a click on the update
button:

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{

    TextBox txt = (TextBox)e.Row.FindControl("txtOrderDate");
    if (txt != null)
    {
       // you can code for the text box to click the update hyperlink
       // for a sample: http://www.societopia.net/samples/datagrid_7c.aspx
      //if then you wish to disable the body onKeyPress event
      //when you found the textobx (which means you are in EditItemTemplate)
     //then add more code to change the attributes of the body
HtmlGenericControl body =
(HtmlGenericControl)Page.Master.FindControl("bodymaster");

    }
}

Show quoteHide quote
"Roberto Kohler" wrote:

> How can I tell if the grid is showing me the "edit command button" or the
> "update command button"
> I need to figure out a way for an event handler to know the "state" of a
> gridview.
> I want the ENTER key to do one thing if I am in "edit mode", and another
> thing if I am in "update mode".
>
> If I am editing a row in a gridView, then the ENTER key should fire the
> onclick event for the "update command button" of "the row I am editing".
> If I am not editing a row, then the ENTER key should fire the onclick event
> for a submit button I have somewhere else on that form.
>
>
>