By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

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

P: n/a
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("resp onsible")
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("stat us")
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!!!!

Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"ja***@cyberpine.com" wrote:
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("resp onsible")
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("stat us")
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!!!!

Nov 19 '05 #2

P: n/a
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

"ja***@cyberpine.com" wrote:
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("resp onsible")
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("stat us")
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!!!!

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.