views:

59

answers:

2

i m using an gridview in which pagingsize is 5 when the next page is clicked it returns empty data. but actually it has 12 datas.im using sql as back end and asp.net c# and the data r calculated at the run time and displayed. im using this code

<asp:GridView ID="GridView_attendancereports"  BorderWidth="1px" BorderColor="#DBDBDA" runat="server" AutoGenerateColumns="False" CssClass="Grid" HeaderStyle-BackColor="#7E7E7C" Width="700px" AllowPaging="True" AllowSorting="True" OnPageIndexChanging="GridView_attendancereports_PageIndexChanging" PageSize="5"  >
A: 

try rebinding to your datasource.

adrianos
+1  A: 

you need to rebind in page index changing event like

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    DataTable dt = GetAllCity();// you need to get here again data from database or from some other sources as you have, to populate your gridview properly
    GridView1.DataSource = dt.DefaultView;
    GridView1.DataBind();
}
Muhammad Akhtar
protected void GridView_attendancereports_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView_attendancereports.PageIndex = e.NewPageIndex; GridView_attendancereports.DataSource = dt; GridView_attendancereports.DataBind(); }im using this code and here , only first page is displayed when 2 is clicked it display empty field
Anand
Are you populating the data in variable dt... EVEN DURING POST BACK... or are you populating the dt only during the initial load.
The King
your code seems to OK, you need to check in PageIndexChanging event, your datatable, weather it is empty or have data?
Muhammad Akhtar
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e){ GridView1.PageIndex = e.NewPageIndex; GridView1.DataSource = dt.DefaultView; GridView1.DataBind();}it also dosent work.yes,i m populating the data in the variable dt.
Anand
hi king,dt variable is used during postback also
Anand
@Anand, have you check datatable data here, you can put break point and check datatable (dt) rows
Muhammad Akhtar
hi akhtar'dt dosnt return any data when break point is used to trace it when second page is bclicked
Anand