Mirza Asghir Baig
Mirza Asghir Baig

Reputation: 41

ASP.net Gridview pager button using c#

I have a gridview and it displays hundreds of record now problem is that, if i set autogeneratecolumns=true; then it will also show columns which i don't want to see, if i set false, it will hide the pager, now i want to make a pager buttons to move navigate to next and previous records. thanks

<PagerTemplate>              
    <asp:Button ID="Button3" runat="server" Text="next" />        
</PagerTemplate>

I have added a button in pager templete but don't know what command I should pass it to fetch next records.

Upvotes: 1

Views: 885

Answers (2)

Stay Foolish
Stay Foolish

Reputation: 3746

You can do something like that

For the previous command CommandName="Previous" OnCommand="ChangePage"

for the next command CommandName="Next" OnCommand="ChangePage"

You can set the page number for the CommandArgument

On the server side, you can do something like this

switch (e.CommandName)
{
    case "Previous":
        currentPageNumber = // get that from the commaCommandArgument;
        break; 

    case "Next":
        currentPageNumber = Int32.Parse(lblCurrentPage.Text) + 1; 
        break; 
}

and then you can bind the data

Upvotes: 1

Esha Garg
Esha Garg

Reputation: 144

protected void gvEmailProject_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
    {
        gvEmailProject.PageIndex = e.NewPageIndex;
        GridFill();
    }

Upvotes: 0

Related Questions