Save the recordinside of a textbox by hitting "Enter key" in gridview

just hitting the "Enter" key.
I have textboxes( item template)  inside of a gridview  and a form view

((TextBox)row.Cells[11].FindControl("TextBox2")).Text;

The use can enter a number inside of the textbox and click save button to be able to save the record that they just entered.

Is there anyway the user can just hit the "Enter" key to be able to save the record that they just entered? the user want to be able to save the record by just hitting the "enter" key.. I have no idea how I am going to so this..

I am using asp.net 2.0 c#..
jung1975Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Elvio Lujan.Net Senior DeveloperCommented:
<script>
function doFocus(key)
{
    if(key == 13) document.getElementById('theIdOfTheButton').focus();
}
</script>

and in the rowdatabound

((TextBox)e.Row.Cells[11].FindControl("TextBox2")).Attributes.Add("onkeydown", "doFocus(window.event.keyCode);");
jung1975Author Commented:
Thanks, but I don;t understand your code:   if(key == 13)??

and Is this code "((TextBox)e.Row.Cells[11].FindControl("TextBox2")).Attributes.Add("onkeydown", "doFocus(window.event.keyCode);");"  will let the user save the record that they just entered inside of textbox in gridview?

Elvio Lujan.Net Senior DeveloperCommented:
the functionally of the comment posted is: when the user press the enter key in the textbox then set the focus to the save button... it's like the user do click on the button

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jung1975Author Commented:
Thanks, but I am getting an error says: ArgumentOutofRangeException was unhandled by user code. Specified argument ws out of the range of valid values" I made sure that Textbox2 is Cells[11]...

I am not sure what I am doing wrong?


Here is the code

 function doFocus(key)
{
    if(key == 13) document.getElementById('Button2').focus();
}
 
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        ((TextBox)e.Row.Cells[11].FindControl("TextBox2")).Attributes.Add("onkeydown", "doFocus(window.event.keyCode);");
    }
}
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.