hi!
i am using datagrid to display data. my aim is i want to give a paging bydefault in datagrid display 10 rows only. and 11th row onwards it goes to the 2nd page. please give a code to this.
thanks
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Anusha Srivastava41 reputationPosted Mar 31, 2010, 9:20 PM EDT
Go to datagrid properties and assign PageButtonCount to 10,choose Mode,
And create event for PageIndexChanged in d properties.
like write OnPageIndexChanged="dgClient_PageIndexChanged" in the source.
Now write code in .cs file--
protected void dgClient_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
try
{
dgClient.CurrentPageIndex = e.NewPageIndex;
BindClientMaster();
}
catch (Exception ex)
{
throw ex;
}
Good Luck.
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 31, 2010, 9:44 PM EDT
asp:DataGrid id="dtgCusts" Width="700" Cellpadding="2" Cellspacing="0" Gridlines="Horizontal" HeaderStyle-BackColor="IndianRed" HeaderStyle-Font-Bold="True" HeaderStyle-Font-Name="Verdana" HeaderStyle-Font-Size="12px" HeaderStyle-ForeColor="White" ItemStyle-BackColor="Gainsboro" ItemStyle-Font-Name="verdana" ItemStyle-Font-Size="12px" AllowPaging="True" OnPageIndexChanged="GridPageIndexChanged" PageSize="10" PagerStyle-Mode="NumericPages" PagerStyle-Position="Top" PagerStyle-HorizontalAlign="Center" PagerStyle-CssClass="pageLinks" AllowSorting="True" runat="server" />Here is the page index changed event
private void GridPageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
//Bind the DataGrid again with the Data Source
DataGrid1.DataSource = dataSet1;
DataGrid1.DataBind();
}
Please mark as answer if it helps.