"Rob" <an*******@disc ussions.microso ft.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:
//************Ite mDataBound***** *************** ******
// placing a bookmark against the first column
LiteralControl anchor = new LiteralControl( );
anchor.Text = "<a name=\"" + itemCount.ToStr ing() + "\">";
itemCount ++;
e.Item.Cells[0].Controls.Add(a nchor);
//************Ite mDataBound***** *************** ******
Then in the EditCommand event method add the following code to get the
browser to jump to the item when the page reloads:
//*************Ed itCommand *************** ***********
System.Text.Str ingBuilder jScript = new System.Text.Str ingBuilder();
jScript.Append( "<script language=\"Java Script\">");
jScript.Append( "location.href= \"#");
jScript.Append( e.Item.ItemInde x.ToString());
jScript.Append( "\";");
jScript.Append( "</script>");
this.RegisterCl ientScriptBlock ("Bookmark", jScript.ToStrin g());
//************Edi tCommand *************** **********
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