Introduction:
In this article you learn about to apply custom page index
for grid view...
This Concept is very simple to apply page index using dropdown
list. Here i share the code to apply custom paging using dropdown list..
Design Code:
<div>
<asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="GridView1_PageIndexChanging">
</asp:GridView>
</div>
<div>
<span style="color: Maroon;">Page Index </span>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</div>
|
Server code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
for (Int64 i = 0; i < GridView1.PageCount; i++)
{
DropDownList1.Items.Add(i.ToString());
}
}
}
|
void bindgrid()
{
//Write the code for
bind the data in grid view.
GridView1.AllowPaging = true;
GridView1.DataSource = dt;
GridView1.DataBind();
}
|
Here we write the code selected change event for dropdown
and grid view index change
protected void
DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.PageIndex =
DropDownList1.SelectedIndex;
GridViewPageEventArgs ea = new GridViewPageEventArgs(GridView1.PageIndex);
GridView1_PageIndexChanging(sender,
ea);
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindgrid();
}
|
I hope you like this article. Post your comment here..
0 comments:
Post a Comment