Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PageIndexChanging in GridView in ASP.NET

Tags:

I have a gridview which I am using to display a dataset result. The problem is I am using paging in it. But when I click on the page # it says that I haven't handled the event. Do I need to rebind the dataset???

Thanks

like image 406
JCTLK Avatar asked Jan 12 '11 05:01

JCTLK


2 Answers

Try the following code:

protected void grdView_PageIndexChanging(object sender, GridViewPageEventArgs e) {     FillGrid();     grdView.PageIndex = e.NewPageIndex;     grdView.DataBind(); } 
like image 152
KGWR Avatar answered Sep 28 '22 04:09

KGWR


Try it

In the pageload

protected void Page_Load(object sender, EventArgs e) {     if (!Page.IsPostBack)     {         loadGrid();     } } 

In the pageindexchanging

private void loadGrid() {     using (your_bankEntities context = new your_bankEntities()) //use your connection .edmx     {         var jmDados = (from jm in context.yourdbo  orderby jm.your fieldkey                            select new                            {                                jm.Field1,                                jm.Field2,                                jm.Field3,                                jm.Field4,                                ........                                 jm.n                             }).ToList();         GridView1.DataSource = jmDados;          GridView1.DataBind();     } } 

In the pageindexchanging

GridView1.PageIndex = e.NewPageIndex;  loadGrid(); 
like image 24
user2714046 Avatar answered Sep 28 '22 05:09

user2714046