You cound also try
Public Shared Sub SetFocus(ByVal control As Control)
If control.Page Is Nothing Then
Throw New ArgumentExcepti on("The Control must be added to a Page
before you can set the IntialFocus to it.")
End If
'If the control is enabled and visible select it
If control.Visible And control.EnableV iewState Then
If control.Page.Re quest.Browser.J avaScript = True Then
' Create JavaScript
Dim s As StringBuilder = New StringBuilder
s.Append(vbCrLf + "<SCRIPT LANGUAGE='JavaS cript'>" + vbCrLf)
s.Append("<!--" + vbCrLf)
s.Append("funct ion SetInitialFocus ()" + vbCrLf)
s.Append("{" + vbCrLf)
s.Append(" try " & vbCrLf)
s.Append(" {" & vbCrLf)
s.Append(" document.")
' Find the Form
Dim p As control = control.Parent
While Not (TypeOf p Is System.Web.UI.H tmlControls.Htm lForm)
p = p.Parent
End While
s.Append(p.Clie ntID)
s.Append("['")
s.Append(contro l.UniqueID)
' Set Focus on the selected item of a RadioButtonList
If TypeOf control Is RadioButtonList Then
Dim rbl As RadioButtonList = control
If Not rbl Is Nothing Then
Dim suffix As String = "_0"
Dim t As Int32 = 0
Dim li As ListItem
For Each li In rbl.Items
If li.Selected Then
suffix = "_" + t.ToString()
Exit For
End If
t = t + 1
Next
s.Append(suffix )
End If
End If
' Set Focus on the first item of a CheckBoxList
If TypeOf control Is CheckBoxList Then
s.Append("_0")
End If
s.Append("'].focus();" + vbCrLf)
s.Append(" }catch(e){}" & vbCrLf) ' close the try, catch
block
s.Append("}" + vbCrLf)
If control.Page.Sm artNavigation Then
s.Append("windo w.setTimeout(Se tInitialFocus, 500);" +
vbCrLf)
Else
s.Append("windo w.onload = SetInitialFocus ;" + vbCrLf)
End If
s.Append("// -->" + vbCrLf)
s.Append("</SCRIPT>" + vbCrLf)
' Register Client Script
control.Page.Re gisterClientScr iptBlock("Initi alFocus",
s.ToString())
End If
End If
End Sub
"ad" <ad@wfes.tcc.ed u.tw> wrote in message
news:On******** ******@TK2MSFTN GP12.phx.gbl...
I used ASP.NET 2.0.
When I edit a row in a GridView.
How can I set the focus to the first editable column?