Data grid pageing with EnableViewState = False turned on

B

Brian Henry

Hi,

I want EnableViewState = false turned on to optimize the end output page (it
was over 600KB with it on) but when i turn it off, our pageing functionality
no longer works mainly the
PageIndexChanged event no longer fires, how do you handle this with enable
view state as false? thanks!
 
B

Brian Henry

but, as i said the problem is that the page index changed even is never
fired...
 
B

Brian Henry

hi, i already am data binding at page load and when the even happens, but
stil lthe Page Index Change event never fires when the currentpageindex is
changed
 
S

Steven Cheng[MSFT]

Hi Brian,

In addition, are you using custom paging or the buildin paging support?
Have you set the AllowPaging property and AllowCustomPaging? If you're
using the buildin paging rather than custom paging, you need to set
AllowPaging as "true" and AllowCustomPaging as "false".
Here is a demo page I made using the buildin paging function and with the
EnableViewState as false:
You may have a try on your side to see whether it can provide any clues:
================aspx page==================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>PagingGrid</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td><FONT face="ËÎÌå"></FONT></td>
</tr>
<tr>
<td>
<asp:DataGrid id="dgPage" runat="server" AutoGenerateColumns="False"
AllowPaging="True" PageSize="6"
EnableViewState="False">
<Columns>
<asp:BoundColumn DataField="index"
HeaderText="Index"></asp:BoundColumn>
<asp:BoundColumn DataField="name"
HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="price"
HeaderText="Price"></asp:BoundColumn>
</Columns>
<PagerStyle PageButtonCount="6" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</td>
</tr>
</table>
</form>
</body>
</HTML>
==========code behind page class=============
public class PagingGrid : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgPage;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Session["DATASOURCE"] = GetDataSource();
}

Bind_Grid();
}

protected DataTable GetDataSource()
{
DataTable tb = new DataTable();
tb.Columns.Add("index");
tb.Columns.Add("name");
tb.Columns.Add("price",typeof(double));

DataRow dr = null;
bool[] flags = {true,false};
for(int i=1;i<=20;++i)
{
dr = tb.NewRow();
dr["index"] = i.ToString();
dr["name"] = "Name" + i.ToString();
dr["price"] = 3.434 * (i%3 +1);

tb.Rows.Add(dr);
}

return tb;
}

protected void Bind_Grid()
{
DataTable tb =(DataTable)Session["DATASOURCE"];
dgPage.DataSource = tb;
dgPage.DataBind();

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgPage.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgPage_PageIn
dexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void dgPage_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgPage.CurrentPageIndex = e.NewPageIndex;
Bind_Grid();
}
}
=========================================

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
B

Brian Henry

AllowPaging = true
AllowCustomPaging = False
EnableViewState = Flase

those are my settings, i havent worked with it yet today, I'm going to try
at this agian here in a minute and see what happenes..


Steven Cheng said:
Hi Brian,

In addition, are you using custom paging or the buildin paging support?
Have you set the AllowPaging property and AllowCustomPaging? If you're
using the buildin paging rather than custom paging, you need to set
AllowPaging as "true" and AllowCustomPaging as "false".
Here is a demo page I made using the buildin paging function and with the
EnableViewState as false:
You may have a try on your side to see whether it can provide any clues:
================aspx page==================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>PagingGrid</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td><FONT face="ËÎÌå"></FONT></td>
</tr>
<tr>
<td>
<asp:DataGrid id="dgPage" runat="server" AutoGenerateColumns="False"
AllowPaging="True" PageSize="6"
EnableViewState="False">
<Columns>
<asp:BoundColumn DataField="index"
HeaderText="Index"></asp:BoundColumn>
<asp:BoundColumn DataField="name"
HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="price"
HeaderText="Price"></asp:BoundColumn>
</Columns>
<PagerStyle PageButtonCount="6" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</td>
</tr>
</table>
</form>
</body>
</HTML>
==========code behind page class=============
public class PagingGrid : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgPage;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Session["DATASOURCE"] = GetDataSource();
}

Bind_Grid();
}

protected DataTable GetDataSource()
{
DataTable tb = new DataTable();
tb.Columns.Add("index");
tb.Columns.Add("name");
tb.Columns.Add("price",typeof(double));

DataRow dr = null;
bool[] flags = {true,false};
for(int i=1;i<=20;++i)
{
dr = tb.NewRow();
dr["index"] = i.ToString();
dr["name"] = "Name" + i.ToString();
dr["price"] = 3.434 * (i%3 +1);

tb.Rows.Add(dr);
}

return tb;
}

protected void Bind_Grid()
{
DataTable tb =(DataTable)Session["DATASOURCE"];
dgPage.DataSource = tb;
dgPage.DataBind();

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgPage.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgPage_PageIn
dexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void dgPage_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgPage.CurrentPageIndex = e.NewPageIndex;
Bind_Grid();
}
}
=========================================

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
B

Brian Henry

got it working, thanks!

Brian Henry said:
AllowPaging = true
AllowCustomPaging = False
EnableViewState = Flase

those are my settings, i havent worked with it yet today, I'm going to try
at this agian here in a minute and see what happenes..


Steven Cheng said:
Hi Brian,

In addition, are you using custom paging or the buildin paging support?
Have you set the AllowPaging property and AllowCustomPaging? If you're
using the buildin paging rather than custom paging, you need to set
AllowPaging as "true" and AllowCustomPaging as "false".
Here is a demo page I made using the buildin paging function and with the
EnableViewState as false:
You may have a try on your side to see whether it can provide any clues:
================aspx page==================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>PagingGrid</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td><FONT face="ËÎÌå"></FONT></td>
</tr>
<tr>
<td>
<asp:DataGrid id="dgPage" runat="server" AutoGenerateColumns="False"
AllowPaging="True" PageSize="6"
EnableViewState="False">
<Columns>
<asp:BoundColumn DataField="index"
HeaderText="Index"></asp:BoundColumn>
<asp:BoundColumn DataField="name"
HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="price"
HeaderText="Price"></asp:BoundColumn>
</Columns>
<PagerStyle PageButtonCount="6" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</td>
</tr>
</table>
</form>
</body>
</HTML>
==========code behind page class=============
public class PagingGrid : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgPage;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Session["DATASOURCE"] = GetDataSource();
}

Bind_Grid();
}

protected DataTable GetDataSource()
{
DataTable tb = new DataTable();
tb.Columns.Add("index");
tb.Columns.Add("name");
tb.Columns.Add("price",typeof(double));

DataRow dr = null;
bool[] flags = {true,false};
for(int i=1;i<=20;++i)
{
dr = tb.NewRow();
dr["index"] = i.ToString();
dr["name"] = "Name" + i.ToString();
dr["price"] = 3.434 * (i%3 +1);

tb.Rows.Add(dr);
}

return tb;
}

protected void Bind_Grid()
{
DataTable tb =(DataTable)Session["DATASOURCE"];
dgPage.DataSource = tb;
dgPage.DataBind();

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgPage.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgPage_PageIn
dexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void dgPage_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgPage.CurrentPageIndex = e.NewPageIndex;
Bind_Grid();
}
}
=========================================

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top