Datagrid Position of New Line

G

Guest

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
 
G

Guest

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.
 
G

Guest

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.
 
G

Guest

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.
 

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

Top