"Rob" <an*******@discussions.microsoft.com> wrote in message news:<00****************************@phx.gbl>...
Hello,
I have a <DIV> in my Datagrid which produces scrollbars
when it is populated. When I click the Edit button in the
edit comand column I need to be able to maintain the
scroll position. According to MSDN, setting
SmartNavigation="True" in the @Page directive will achieve
this but unfortunately it does not, does anybody know how
to do this? I have found an article explaining how to do
this with c# (by creating a Inet Explorer behaviour) but I
am using vb and want to keep it as simple as possible if I
can?
Cheers
Rob
Hi Rob, not sure smartnav works well with grids, i doubt itll keep
position within DIV, it only keeps scroll position on the main scroll
bar.
Anyway , we did the following to keep edit position on the edit
selected with a DIV:
add the follwing to the main class variables of the form:
private int itemCount = 0;
In the ItemDataBound event of your grid add the following code to add
a number bookmark to each row in the grid that is created:
//************ItemDataBound************************* *
// placing a bookmark against the first column
LiteralControl anchor = new LiteralControl();
anchor.Text = "<a name=\"" + itemCount.ToString() + "\">";
itemCount ++;
e.Item.Cells[0].Controls.Add(anchor);
//************ItemDataBound************************* *
Then in the EditCommand event method add the following code to get the
browser to jump to the item when the page reloads:
//*************EditCommand **************************
System.Text.StringBuilder jScript = new System.Text.StringBuilder();
jScript.Append("<script language=\"JavaScript\">");
jScript.Append("location.href=\"#");
jScript.Append(e.Item.ItemIndex.ToString());
jScript.Append("\";");
jScript.Append("</script>");
this.RegisterClientScriptBlock("Bookmark", jScript.ToString());
//************EditCommand *************************
You may then want to add the above edit commmand code into any method
that ou want to retain position, e.g. UpdateCommand and CancelCommand.
We put the above code into a function and passed in the ItemIndex from
whatever event function was called (SelectCommand, EditCommmand,
UpdateCOmmand, CancelCommand
Hope that helps.
Ryan Harvey, IBM