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

link|improve this question
feedback

1 Answer

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.

link|improve this answer
1  
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 at 15:25
feedback

Your Answer

 
or
required, but never shown

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