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

Datagrid Position of New Line

P: n/a
In ASP.NET 1.1, I have SmartNavigation turned on so that the user's focus
will remain on the line in the datagrid they choose to edit.

When the user chooses to add a new line in the datagrid, rather than only
show that line, I'm displaying all items in the datagrid, with the new line
at the bottom.
With grdResults
' Set editing on last row
.EditItemIndex = .Items.Count
.DataSource = ds
.DataBind()
End With

This is fine if the number of items in the grid doesn't go beyond a page.
After that, the new line is not the focus, and the user needs to scroll down
the page to access the new line. How can I set the focus to that new line?
Here is my code in the Page_Load event:
If Not Page.IsPostBack Then
Try
Me.LoadGrid()

Catch ex As Exception
ShowMessageBox(Me, ex.Message)
End Try
End If

Dec 2 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
If your datagrid has more than one page and you want the last page to be
displayed, calculate the last page number by dividing
grdResults.Items.Count/grdResults.PageSize then set the
grdResults.CurrentPageIndex to that number before doing the DataBind and
after you set the EditItemIndex to the Items.Count.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Richard" wrote:
In ASP.NET 1.1, I have SmartNavigation turned on so that the user's focus
will remain on the line in the datagrid they choose to edit.

When the user chooses to add a new line in the datagrid, rather than only
show that line, I'm displaying all items in the datagrid, with the new line
at the bottom.
With grdResults
' Set editing on last row
.EditItemIndex = .Items.Count
.DataSource = ds
.DataBind()
End With

This is fine if the number of items in the grid doesn't go beyond a page.
After that, the new line is not the focus, and the user needs to scroll down
the page to access the new line. How can I set the focus to that new line?
Here is my code in the Page_Load event:
If Not Page.IsPostBack Then
Try
Me.LoadGrid()

Catch ex As Exception
ShowMessageBox(Me, ex.Message)
End Try
End If

Dec 2 '05 #2

P: n/a
Thanks Phillip, but I'm not using datagrid paging. I just need to know how to
set focus to the blank datagrid row at the bottom of the web form. If the
grid has only a few items, this isn't an issue because the user can see it
without scrolling down the web page. But when the grid has say 25 items, and
the user wants to create a new item, the last row is out of view until the
user scrolls vertically.

"Phillip Williams" wrote:
If your datagrid has more than one page and you want the last page to be
displayed, calculate the last page number by dividing
grdResults.Items.Count/grdResults.PageSize then set the
grdResults.CurrentPageIndex to that number before doing the DataBind and
after you set the EditItemIndex to the Items.Count.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Richard" wrote:
In ASP.NET 1.1, I have SmartNavigation turned on so that the user's focus
will remain on the line in the datagrid they choose to edit.

When the user chooses to add a new line in the datagrid, rather than only
show that line, I'm displaying all items in the datagrid, with the new line
at the bottom.
With grdResults
' Set editing on last row
.EditItemIndex = .Items.Count
.DataSource = ds
.DataBind()
End With

This is fine if the number of items in the grid doesn't go beyond a page.
After that, the new line is not the focus, and the user needs to scroll down
the page to access the new line. How can I set the focus to that new line?
Here is my code in the Page_Load event:
If Not Page.IsPostBack Then
Try
Me.LoadGrid()

Catch ex As Exception
ShowMessageBox(Me, ex.Message)
End Try
End If

Dec 2 '05 #3

P: n/a
Hi Richard,

Assuming that the datagrid is the last element on the page, you might add
the following line after the DataBind step:
Page.RegisterStartupScript("ScrollTop", "<script
language='JavaScript'>document.body.scrollTop =100000;</script>")

Where 100000 is an arbitrary large number that would cause the browser to
scroll to the end of the page.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Richard" wrote:
Thanks Phillip, but I'm not using datagrid paging. I just need to know how to
set focus to the blank datagrid row at the bottom of the web form. If the
grid has only a few items, this isn't an issue because the user can see it
without scrolling down the web page. But when the grid has say 25 items, and
the user wants to create a new item, the last row is out of view until the
user scrolls vertically.

"Phillip Williams" wrote:
If your datagrid has more than one page and you want the last page to be
displayed, calculate the last page number by dividing
grdResults.Items.Count/grdResults.PageSize then set the
grdResults.CurrentPageIndex to that number before doing the DataBind and
after you set the EditItemIndex to the Items.Count.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Richard" wrote:
In ASP.NET 1.1, I have SmartNavigation turned on so that the user's focus
will remain on the line in the datagrid they choose to edit.

When the user chooses to add a new line in the datagrid, rather than only
show that line, I'm displaying all items in the datagrid, with the new line
at the bottom.
With grdResults
' Set editing on last row
.EditItemIndex = .Items.Count
.DataSource = ds
.DataBind()
End With

This is fine if the number of items in the grid doesn't go beyond a page.
After that, the new line is not the focus, and the user needs to scroll down
the page to access the new line. How can I set the focus to that new line?
Here is my code in the Page_Load event:
If Not Page.IsPostBack Then
Try
Me.LoadGrid()

Catch ex As Exception
ShowMessageBox(Me, ex.Message)
End Try
End If

Dec 2 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.