Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with focus() in a datagrid!

Status
Not open for further replies.

iRead

Programmer
Joined
Mar 12, 2004
Messages
25
Location
US
I’m trying to set the focus to the first textbox of the row I’m editing in a datagrid when I press the edit button on the row. Problem is I don’t know how to reference the textbox.

I’ve tried:
// Set the script to focus and select the TextBox

ltlScript = "((TextBox)e.Item.Cells[1].Controls[1]).focus()";
and
ltlScript = "('DataBinder.Eval(Container.DataItem, 'FirstName')').focus()";

neither work. Any suggestions on this?

Thank you!
iRead
 
If the "firstName" is the 2nd column in the DataGrid and it is bound as a TextBox then you can access it by:
Code:
  TextBox firstNameText = (TextBox)e.Item.Cells[1].Controls[0];
If the 'firstName" is the first column in the DataGrid then the TextBox control is accessed by:
Code:
TextBox firstNameText = (TextBox)e.Item.Cells[0].Controls[0];
If the column is bound as a TextBox then is always the 0th control in a cell's Controls collection.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top