user1848942
user1848942

Reputation: 355

how to fix page numbering in gridviev?

I can't find the way to fix page numbering in gridviev that they didn't change position depending on the contents of the gridview.

HTML:

<asp:GridView ID="tableResults" runat="server" DataSourceID="sourcePoints"
 CssClass = "table table-bordered" AutoGenerateColumns="False" OnDataBound="tableResults_Bound"
 OnRowDataBound = "tableResults_DataBound" DataKeyNames="i_id" PageSize="4" AllowPaging="true"
 AutoGenerateDeleteButton="True" OnRowDeleted="tableResults_RowDeleted" Height="300px" Width="100%"
 AutoGenerateEditButton = "True" OnRowUpdating="tableResults_RowUpdating"
 AllowSorting="true" OnRowUpdated="tableResults_RowUpdated" BorderStyle="None">

Upvotes: 1

Views: 93

Answers (2)

Yusubov
Yusubov

Reputation: 5843

In short: There are few tricks while using page numbering in asp.net GridView control.

For Paging to work, your datasource must support it. If it does not, like a DataTable, then you have to do this yourself.

This code below might help you:

OnPageIndexChanging="myGridview_PageIndexChanging"

protected void myGridview_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView gv = (GridView)sender;
    DataView dv = gv.DataSource as DataView;
    DataTable dataTable = dv.Table;

    gv.DataSource = myDataTable;
    gv.PageIndex = e.NewPageIndex;
    gv.DataBind();
}

References to look:

Here you are some ** complementary posts** that explains them step-by-step:

Upvotes: 1

4b0
4b0

Reputation: 22323

Use PagerStyle.

 <PagerStyle cssClass="YourPagerCss" HorizontalAlign="Right" /> 

And define your css .

For details see a link. http://www.west-wind.com/weblog/posts/2007/Aug/18/GridView-and-Paging-Alignment

Upvotes: 1

Related Questions