How to determine the "state" of a GridView

R

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.
 
P

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");

}
}
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top