Hello,
I have really no experience with the GridView control but I put together a small example just for fun. It maintains the scroll position for me.
What it does:
- has a simple gridview, only AutoGenerateEditButton = true is set in the codebehind
- it is bound to an arraylist (it is not an updateable datasource, but the edit link is displayed before each row and postback if you click it)
- each round trip I rebind the grid (it fills numbers 0-99 then you press edit it fills 99-0 and so on) just for "visualization"
- it handles the RowEditing in the codebehind, but do nothing
- tested in ie6/firefox
Here it is, would you please check it?:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test3.aspx.cs" Inherits="ForumTest.test.test3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="TheScriptManager" EnablePartialRendering="true" runat="server" />
<p><%= "Just testing that we have partial postback :) " + DateTime.Now.ToString( ) %></p>
<asp:Button ID="btn" runat="server" text="Independent postback from gridview just for test"/>
<div style="overflow: scroll; height: 200px;">
<asp:UpdatePanel id="up1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="grid1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:UpdateProgress runat="server" DisplayAfter="0">
<ProgressTemplate><div style="position: absolute; top: 0; left: 0; background-color: Red;">PROGRESS</div></ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace ForumTest.test
{
public partial class test3 : System.Web.UI.Page
{
private bool m_FlipState = false;
/// <summary>
/// Gets or sets FlipState.
/// </summary>
public bool FlipState
{
get
{
return ( bool )( this.ViewState[ "m_FlipState" ] ?? m_FlipState );
}
set
{
this.ViewState[ "m_FlipState" ] = m_FlipState = value;
}
}
protected override void OnInit( EventArgs e )
{
this.grid1.RowEditing += new GridViewEditEventHandler( grid1_RowEditing );
base.OnInit( e );
}
protected void Page_Load( object sender, EventArgs e )
{
System.Collections.ArrayList myList = new ArrayList( );
if( !this.FlipState )
{
for( int i = 0; i < 100; i++ )
{
myList.Add( i.ToString( ) );
}
}
else
{
for( int i = 99; i >= 0; i-- )
{
myList.Add( i.ToString( ) );
}
}
this.FlipState = !this.FlipState;
this.grid1.AutoGenerateEditButton = true;
this.grid1.DataSource = myList;
this.grid1.DataBind( );
}
protected void grid1_RowEditing( object sender, GridViewEditEventArgs e )
{
// throw new Exception( "The method or operation is not implemented." );
}
}
}