I'm trying to set the focus to a textbox in a datagrid when the user starts editing the grid.
I copied some code from 4Guys but it's not happening for me
The output to the text box is in the form:
LayerGrid__ctl3__ctl0
But the source says this:
<input name="LayerGrid:_ctl3:_ctl0"
And I get no focus.
Granted the 4Guys code must have been for a templated grid because they know the name of the textbox that pops up for editing
descTB = dgPopularFAQs.Items(e.Item.ItemIndex).Cells(2).FindControl("txtDesc")
but I don't think I know that in my case. I'm just using bound columns.
Any suggestions?
I copied some code from 4Guys but it's not happening for me
Code:
' Create a reference to the TextBox
Dim descTB As TextBox
descTB = LayerGrid.Items(e.Item.ItemIndex).Cells(2).Controls(0)
Me.txtStatus.Text = descTB.ClientID.ToString
'Set the script to focus and select the TextBox
RegisterStartupScript("focus", "<script language=""JavaScript"">" & vbCrLf & _
vbTab & "Form1." & descTB.ClientID & ".focus();" & _
vbCrLf & vbTab & "Form1." & descTB.ClientID & ".select();" & _
vbCrLf & "<" & "/script>")
The output to the text box is in the form:
LayerGrid__ctl3__ctl0
But the source says this:
<input name="LayerGrid:_ctl3:_ctl0"
And I get no focus.
Granted the 4Guys code must have been for a templated grid because they know the name of the textbox that pops up for editing
descTB = dgPopularFAQs.Items(e.Item.ItemIndex).Cells(2).FindControl("txtDesc")
but I don't think I know that in my case. I'm just using bound columns.
Any suggestions?