Setting Focus on Edit Row in Datagrid - how do I reference new clientid name???

J

jason

Hello and Good Day. REALLY LOST.

Running ASP.NET 1.1

Becuase I think I'm using my own controls smartnavigation does not
appear to work for me.

Stardard issue: I've got a datagrid thats displaying pages and pages of
rows. When I edit some row below pages 1 the post refreshes back to
page one, requiring me to page down to do the input.

I have found some C# code that looks promising, but can't seem to make
it work in VB ..

I'm just taking shots in the dark now.

When I attempt to execute this code I get javascript error that
responsible is not defined. when I view source, ofcourse the datagrid
has used clientid to rename ids.. something like:
id="UserGrid__ctl2_responsible"

Below is my really bad attempt at getting this to work:

<beginning of code>

Public Sub UserGrid_Edit (Source As Object, E As
DataGridCommandEventArgs)
UserGrid.EditItemIndex = E.Item.ItemIndex
BindData()

' the below code is to force dropdown to display preset value in
database first so
'update does not take the wrong value!

'make dropdowns remember current value
Dim ddlResponsible As DropDownList =
UserGrid.Items(e.Item.ItemIndex).FindControl("responsible")
Dim colIndex As Integer = 2
Dim resp As String = CType(e.Item.Cells(colIndex).Controls(1),
Label).Text.Trim
For I As Integer = 0 To ddlResponsible.Items.Count - 1
If ddlResponsible.Items(I).Text.Trim.Equals(resp) Then
ddlResponsible.SelectedIndex = I
Exit For
End If
Next

Dim ddlstatus As DropDownList =
UserGrid.Items(e.Item.ItemIndex).FindControl("status")
Dim colIndexb As Integer = 3
Dim stat As String = CType(e.Item.Cells(colIndexb).Controls(1),
Label).Text.Trim
For I As Integer = 0 To ddlstatus.Items.Count - 1
If ddlstatus.Items(I).Text.Trim.Equals(stat) Then
ddlstatus.SelectedIndex = I
Exit For
End If
Next

'here's where trying to focus, but can't figure out how to address the
new id

Dim strBuilder As StringBuilder = New StringBuilder()
strBuilder.Append("<script language='javascript'>function
window.onload(){")
strBuilder.Append("
document.elements(responsible.clientid).focus();")
strBuilder.Append("}"+chr(60)+"/script>")
RegisterStartupScript("FR", strBuilder.ToString)


End Sub

<end of code>

And, while on the subject - is there any way in javascript to just go
to the second field? in this case its a dropdown select.
Here are my two senseless attempts.

<body onload="document.forms[0].fields[1].focus()">

does not work, nor does

<body onload="document.forms[0].elementsbyid((*responsible').focus()">


THANK YOU FOR ANY HELP OR INFORMATION!!!!
 
G

Guest

I have a sample in VB that sets the focus to the edit box:
http://www.webswapp.com/webswapp.aspx?i=11

---
www.societopia.net

Hello and Good Day. REALLY LOST.

Running ASP.NET 1.1

Becuase I think I'm using my own controls smartnavigation does not
appear to work for me.

Stardard issue: I've got a datagrid thats displaying pages and pages of
rows. When I edit some row below pages 1 the post refreshes back to
page one, requiring me to page down to do the input.

I have found some C# code that looks promising, but can't seem to make
it work in VB ..

I'm just taking shots in the dark now.

When I attempt to execute this code I get javascript error that
responsible is not defined. when I view source, ofcourse the datagrid
has used clientid to rename ids.. something like:
id="UserGrid__ctl2_responsible"

Below is my really bad attempt at getting this to work:

<beginning of code>

Public Sub UserGrid_Edit (Source As Object, E As
DataGridCommandEventArgs)
UserGrid.EditItemIndex = E.Item.ItemIndex
BindData()

' the below code is to force dropdown to display preset value in
database first so
'update does not take the wrong value!

'make dropdowns remember current value
Dim ddlResponsible As DropDownList =
UserGrid.Items(e.Item.ItemIndex).FindControl("responsible")
Dim colIndex As Integer = 2
Dim resp As String = CType(e.Item.Cells(colIndex).Controls(1),
Label).Text.Trim
For I As Integer = 0 To ddlResponsible.Items.Count - 1
If ddlResponsible.Items(I).Text.Trim.Equals(resp) Then
ddlResponsible.SelectedIndex = I
Exit For
End If
Next

Dim ddlstatus As DropDownList =
UserGrid.Items(e.Item.ItemIndex).FindControl("status")
Dim colIndexb As Integer = 3
Dim stat As String = CType(e.Item.Cells(colIndexb).Controls(1),
Label).Text.Trim
For I As Integer = 0 To ddlstatus.Items.Count - 1
If ddlstatus.Items(I).Text.Trim.Equals(stat) Then
ddlstatus.SelectedIndex = I
Exit For
End If
Next

'here's where trying to focus, but can't figure out how to address the
new id

Dim strBuilder As StringBuilder = New StringBuilder()
strBuilder.Append("<script language='javascript'>function
window.onload(){")
strBuilder.Append("
document.elements(responsible.clientid).focus();")
strBuilder.Append("}"+chr(60)+"/script>")
RegisterStartupScript("FR", strBuilder.ToString)


End Sub

<end of code>

And, while on the subject - is there any way in javascript to just go
to the second field? in this case its a dropdown select.
Here are my two senseless attempts.

<body onload="document.forms[0].fields[1].focus()">

does not work, nor does

<body onload="document.forms[0].elementsbyid((*responsible').focus()">


THANK YOU FOR ANY HELP OR INFORMATION!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top