i have a gridview in that '> <%-- onkeypress="searchKeyPress(event);" --%> 开发者_开发知识库
if i press enter key in this focus must go to second row same column's textbox....
Hope u understand my question
Thank you
use
if(event.keyCode == 13)
moveToNextElement(event.target);
function moveToNextElement(target) {
//you have the current location target as reference
}
I am assmuing you have a text box in each row of a gridview, and you want to focus the next textbox in the same column on the row below on enter on a particaular textbox.
protected void GridView1_OnDataBound(object source, EventArgs e)
{
for (int index = 0; index <= GridView1.Rows.Count - 1; index++) {
dynamic CurrentTextBox = (TextBox)GridView1.Rows(index).FindControl("yourTextBoxId");
//Set Focus to Next TextBox
if ((index != GridView1.Rows.Count - 1)) {
dynamic NextTextBox = (TextBox)GridView1.Rows(index + 1).FindControl("yourTextBoxId");
CurrentTextBox.Attributes.Add("onkeypress", "setFocus('" + NextTextBox.ClientID + "');");
}
}
}
Write the following javascript function in your aspx page.
function setFocus(Target)
{
if(window.event.keyCode=="13")
document.getElementById(Target).focus();
}
精彩评论