M
Martin Bischoff
Hi,
I have a datagrid, which I bind to an array of objects stored in the
session. I'm using numeric paging on the datagrid, which works fine
until the number of pages is higher than PageButtonCount.
This is what happens, when I have 30 pages and PageButtonCount is set to 10:
- Paging works as expected as long as I click page 1..10.
- clicking the ellipsis link, correctly displays page 11 and links to
pages 11 to 20.
- If I now click on the link for page 12, the grid will display page 3
instead. If I set a breakpoint in PageIndexChanged, I can see that
e.NewPageIndex is 2.
Please see below for a code sample.
What am I doing wrong? How can this problem be fixed?
Thanks for any help,
Martin
Here are the relevant code extracts:
ASPX:
-----------------------------
<asp:Label id=Label1 runat="server">Label</asp:Label>
<aspataGrid id=DataGrid1
style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 40px"
runat="server"
AutoGenerateColumns="False" AllowPaging="True">
<columns>
<asp:BoundColumn DataField="ProductID"></asp:BoundColumn>
<asp:BoundColumn DataField="message"></asp:BoundColumn>
</Columns>
<pagerstyle position="TopAndBottom" mode="NumericPages">
</PagerStyle>
</aspataGrid>
-----------------------------
Codebehind (ASPX.CS):
-----------------------------
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
DataTable LoadDataSource()
{
DataTable dt = new DataTable();
dt.Columns.Add("ProductID", typeof(int));
dt.Columns.Add("message", typeof(string));
DataRow dr;
for(int idx=0;idx< 300;idx++)
{
dr = dt.NewRow();
dr[0] = idx;
dr[1] = "Message " + idx.ToString();
dt.Rows.Add(dr);
}
return dt;
}
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid1.DataSource = LoadDataSource();
DataGrid1.DataBind();
DataGrid1.EnableViewState = false;
}
private void DataGrid1_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
Label1.Text = e.NewPageIndex.ToString();
DataGrid1.DataSource = LoadDataSource();
DataGrid1.DataBind();
}
-----------------------------
I have a datagrid, which I bind to an array of objects stored in the
session. I'm using numeric paging on the datagrid, which works fine
until the number of pages is higher than PageButtonCount.
This is what happens, when I have 30 pages and PageButtonCount is set to 10:
- Paging works as expected as long as I click page 1..10.
- clicking the ellipsis link, correctly displays page 11 and links to
pages 11 to 20.
- If I now click on the link for page 12, the grid will display page 3
instead. If I set a breakpoint in PageIndexChanged, I can see that
e.NewPageIndex is 2.
Please see below for a code sample.
What am I doing wrong? How can this problem be fixed?
Thanks for any help,
Martin
Here are the relevant code extracts:
ASPX:
-----------------------------
<asp:Label id=Label1 runat="server">Label</asp:Label>
<aspataGrid id=DataGrid1
style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 40px"
runat="server"
AutoGenerateColumns="False" AllowPaging="True">
<columns>
<asp:BoundColumn DataField="ProductID"></asp:BoundColumn>
<asp:BoundColumn DataField="message"></asp:BoundColumn>
</Columns>
<pagerstyle position="TopAndBottom" mode="NumericPages">
</PagerStyle>
</aspataGrid>
-----------------------------
Codebehind (ASPX.CS):
-----------------------------
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
DataTable LoadDataSource()
{
DataTable dt = new DataTable();
dt.Columns.Add("ProductID", typeof(int));
dt.Columns.Add("message", typeof(string));
DataRow dr;
for(int idx=0;idx< 300;idx++)
{
dr = dt.NewRow();
dr[0] = idx;
dr[1] = "Message " + idx.ToString();
dt.Rows.Add(dr);
}
return dt;
}
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid1.DataSource = LoadDataSource();
DataGrid1.DataBind();
DataGrid1.EnableViewState = false;
}
private void DataGrid1_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
Label1.Text = e.NewPageIndex.ToString();
DataGrid1.DataSource = LoadDataSource();
DataGrid1.DataBind();
}
-----------------------------