2014年7月13日 星期日

[RESOLVED] GridView disaper when paging


HI


Could someon help me with Gridview which disaper if i click on one of the  pages


My Code:


asp:GridView
ID="GridOut"
runat="server"
AutoGenerateColumns="false"
AllowPaging="true"
PageSize="20"
OnPageIndexChanging="GridPage">


<Columns>


<asp:BoundField
DataField="UserName"
HeaderText="Name"
/>


<asp:BoundField
DataField="UserAddress"
HeaderText="Address"
/> 


Columns>


asp:GridView>


protected void GetUser_Submit(object sender, EventArgs e)        


 {


<PSObject>
CollectionforGreadView= getUser.GetUserAccount(ConnectAD); //Hier i get my my collection.


            GridOut.DataSource = CollectionforGreadView;


            GridOut.DataBind();


}


 


void
GridPage(
object
sender,
GridViewPageEventArgs
e)


        {


            GridOut.PageIndex = e.NewPageIndex;


            GridOut.DataBind();  


        }


U user master page and if i press GetUser_Submitt button my GridView is filled with Data but if i press
next page it disapers...


Why...


Should i do somthing with postback....


 


Thanks for your answer.



try


void GridPage(object sender, GridViewPageEventArgs e)

{

GridOut.PageIndex = e.NewPageIndex;


}







try to update your method ,


void GridPage(object sender, GridViewPageEventArgs e)

{

GridOut.PageIndex = e.NewPageIndex;

GridOut.DataBind();

}

With following,


void GridPage(object sender, GridViewPageEventArgs e)

{

GridOut.PageIndex = e.NewPageIndex;

GridOut.DataSource = YourData;

GridOut.DataBind();

}









Thanks for your answer...


I tried but the problem is that my Colleciton "CollectionforGreadView" is not Accesible in GridPage method.


I get collection after button click event.



I made Collection public and implemented it but it is still disaper...


Please notcie that i also use masterpage.


Does it have somthing with that to do...



using masterpage doesn't matter. The basic idea is to repopulate your GridView with the updated data after you do the paging and then call DataBind().



protected void GetUser_Submit(object sender, EventArgs e)

{

CollectionforGreadView= getUser.GetUserAccount(ConnectAD); //Hier i get my my collection.

GridOut.DataSource = CollectionforGreadView;
Session("DataSource") = CollectionGreadView;

GridOut.DataBind();

}



void GridPage(object sender, GridViewPageEventArgs e)

{

GridOut.PageIndex = e.NewPageIndex;
DataSource = Session("DataSource");
GridOut.DataSource = DataSource;
GridOut.DataBind();

}

Update your code with above code..Try it and give feedback...You have to use session variable to get the datasource after postback..


Mark my post as Answer if it solve your problem..



Hi,


You can refer the sample about paging in gridview


http://www.nullskull.com/a/1645/aspnet-basics-gridview-from-database-with-paging-sorting-and-editing.aspx


And refer the similar thread:


http://forums.asp.net/t/1902480.aspx/1/10


Hope it can help you


沒有留言:

張貼留言