I know it has been a while, but I am a newbe and your answer shows the most promise. I am trying to have the enter key move me from one column to the next and then down the gridview to the first column on the next row. What I don't understand is the
reference above. If I can identify the e.row.Cell(4) as the cell in which it resides, then what is ".Controls[0]?
leena0711
Member
22 Points
24 Posts
Gridview enter key press event
Aug 23, 2011 10:47 AM|LINK
Hi, I am having gridview with three columns: Item code[Textbox], Qty[Textbox] and ItemName[Label] with AddNewRow button in footer.
I want enter key press to move from 1st cell to 2nd and 2nd to button click.
Please help on above issue.
ASP C# 2.0
Regards,
Leena
SamCasper
Member
690 Points
143 Posts
Re: Gridview enter key press event
Aug 23, 2011 12:45 PM|LINK
Well On RowDataBound Event Of GridView.
Get The Reference Of Both Of TextBoxes
Like
TextBox1 = e.Row.Cell[0].Controls[0] as TextBox;
TextBox2 = e.Row.Cell[1].Controls[0] as TextBox;
TextBox1.Attributes.Add("onkeydown", String.Format( "SwitchOnEnter(event,'{0}');", TextBox2.ClientID) );In Head Of Page use this
<script type="text/javascript"> function SwitchOnEnter(e, NextTextBox) { var keynum var keychar var numcheck if (window.event) // IE { keynum = e.keyCode } else if (e.which) // Netscape/Firefox/Opera { keynum = e.which } if (keynum == 13) { document.getElementById(NextTextBox).focus(); } } </script>The Real PHP.net
Orcas
Orcas Docs
konanki
Contributor
6198 Points
1239 Posts
Re: Gridview enter key press event
Aug 23, 2011 04:01 PM|LINK
protected void AvailLogs_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowType == DataControlRowType.DataRow) && !(e.Row.RowType == DataControlRowType.Header) && !(e.Row.RowType == DataControlRowType.Footer))
{
int Rownumber = e.Row.RowIndex + 1;
e.Row.Attributes.Add("KeyPress", "javascript:ShowSerializedObject(" + Rownumber + ")");
}
}
jjobcorp
Member
9 Points
27 Posts
Re: Gridview enter key press event
Nov 15, 2012 07:11 PM|LINK
I know it has been a while, but I am a newbe and your answer shows the most promise. I am trying to have the enter key move me from one column to the next and then down the gridview to the first column on the next row. What I don't understand is the reference above. If I can identify the e.row.Cell(4) as the cell in which it resides, then what is ".Controls[0]?