I am trying to do paging of data. Basically I am taking a data and want to show it on multi pages. But it is not working. I am using Asp.net and C# for coding. I am using mysql as database.
Code is as follows : ASP code
<asp:DataGrid runat="server" ID="RestData"
AllowPaging="True" PageSize="2"
OnPageIndexChanged="RestData_PageIndexChanged" AllowCustomPaging="True"
PagerStyle-Wrap="False">
<PagerStyle />
</asp:DataGrid>
C# code:
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
public void BindData()
{
RestData.DataSource = call.GetReader(Convert.ToInt32(AreaData.SelectedValue));
//GetReader is function which returns the data reader of mysql
RestData.DataBind();
}
protected void RestData_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
RestData.CurrentPageIndex = e.NewPageIndex;
BindData();
}
Output: It is displaying two rows(as i have given pagesize 2). But I am not able to see next page.
The query should returns more than 2 rows(it does happen when i use repeater but i am not able to do paging in it.
The DataGrid must know what to do when you try to change pages.
In your grid (example comes from my project which is in VB, sorry):
Notice the last line...
Now go to the code view and create the following sub:
As indicated to Rajuu Parmar, there is no
.PageIndex
property for the DataGrid. This is correct. The equivalent property for DataGrid is the.CurrentPageIndex
. Why Microsoft made them different, I have no idea. While you solved the problem (years ago from the date), I'm hoping that you or someone else finds this useful.