GridView - PageIndexChanging not handled
-
I am using the following code to populate a GridView in protected void Button1_Click(object sender, EventArgs e) { String selectCommand = "select top 1000 claimid, formtype, status, totalpaid, paiddate from claim"; SqlDataAdapter ad = new SqlDataAdapter(selectCommand, SqlDataSource1.ConnectionString); DataTable dt = new DataTable(); ad.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } This works, but I have AllowPaging = true, and the first time I click the "Next Page" button, I get a "PageIndexChanging not handled" exception. I have not setup a PageIndexChanging handler, but I didn't think I had to in this case. BTW, when I populate by just setting the GridView1.DataSourceID to a SQLDataSource, the problem does not occur. Paging works fine. What am I doing wrong? Thanks! Mark
-
I am using the following code to populate a GridView in protected void Button1_Click(object sender, EventArgs e) { String selectCommand = "select top 1000 claimid, formtype, status, totalpaid, paiddate from claim"; SqlDataAdapter ad = new SqlDataAdapter(selectCommand, SqlDataSource1.ConnectionString); DataTable dt = new DataTable(); ad.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } This works, but I have AllowPaging = true, and the first time I click the "Next Page" button, I get a "PageIndexChanging not handled" exception. I have not setup a PageIndexChanging handler, but I didn't think I had to in this case. BTW, when I populate by just setting the GridView1.DataSourceID to a SQLDataSource, the problem does not occur. Paging works fine. What am I doing wrong? Thanks! Mark
Hi try this in your pageindexchanging event gridview.pageindex = e.newpageindex String selectCommand = "select top 1000 claimid, formtype, status, totalpaid, paiddate from claim"; SqlDataAdapter ad = new SqlDataAdapter(selectCommand, SqlDataSource1.ConnectionString); DataTable dt = new DataTable(); ad.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind();
Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.
-
I am using the following code to populate a GridView in protected void Button1_Click(object sender, EventArgs e) { String selectCommand = "select top 1000 claimid, formtype, status, totalpaid, paiddate from claim"; SqlDataAdapter ad = new SqlDataAdapter(selectCommand, SqlDataSource1.ConnectionString); DataTable dt = new DataTable(); ad.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } This works, but I have AllowPaging = true, and the first time I click the "Next Page" button, I get a "PageIndexChanging not handled" exception. I have not setup a PageIndexChanging handler, but I didn't think I had to in this case. BTW, when I populate by just setting the GridView1.DataSourceID to a SQLDataSource, the problem does not occur. Paging works fine. What am I doing wrong? Thanks! Mark
You are binding the DataSource manually, so in this case you have to override the PageIndexChanging and PageIndexChanged handler. For example, protected void GridViewXXX_PageIndexChanged(object sender, EventArgs e) { this.SqlDataSourceXXX.SelectCommand = "XXX"; } protected void GridViewXXX_PageIndexChanging(object sender, GridViewPageEventArgs e) { this.GridViewXXX.PageIndex = e.NewPageIndex; }
Welcome to www.softwaretree.net! This website is generated completely by static html pages transforming technology. You can find many excellent audio/video tools there!