SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This should be pretty easy but I can't find it anywhere.

Scenario: DataTable associated to an SPGridView. Every row of the SPGridView is editable and it shows boxes on some of the columns. I put an Update button and I implemented the RowUpdating event which works perfectly.

So, what I want is when the user press the Intro key in the TextBox, this action launch the Update command.

Thanks in advance...

share|improve this question
up vote 0 down vote accepted

Since SPGridView is nothing more then basic GridView with some additions maybe this link can be helpful (at least as starting point):

Handling the Enter key pressed in a GridView's row edit mode

protected void gvChild_RowDataBound(object sender, GridViewRowEventArgs e)
    // if enter key is pressed (keycode==13) call __doPostBack on grid and with 
    // 1st param = gvChild.UniqueID (Gridviews UniqueID)
    // 2nd param = CommandName=Update$  +  CommandArgument=RowIndex
    if ((e.Row.RowState == DataControlRowState.Edit) || 
       (e.Row.RowState == (DataControlRowState.Edit|DataControlRowState.Alternate)))
        e.Row.Attributes.Add("onkeypress", "javascript:if (event.keyCode == 13) { 
            __doPostBack('" + gvChild.UniqueID + "', 'Update$" + 
           e.Row.RowIndex.ToString() + "'); return false; }");

I never tested this code so here is little disclaimer:

Specific SP problems can arise on page postback. I am not sure about gvChild.UniqueID part of the sample code. I think Control.ClientID suits better.

share|improve this answer
I changed a little bit, but it worked like a charm. Instead of generating the __doPostBack function manually I call to String sPostBackScript = ClientScript.GetPostBackClientHyperlink(this.gvChild, "Update$" + e.Row.RowIndex);. But it was really helpful, thanks. PS: Remember put AutoPostBack="False". – Dani Rodríguez Jan 24 '12 at 15:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.