GridView分页后点击后面页面显示空白
我是初学者,请多指教。
如题,将GridView和数据库查询结果绑定起来后,点击查询出了结果。但是点击第二面或者其他的,就直接变空白了。
前台:
<asp:GridView ID="ResGridView" runat="server" DataSourceID="SqlDataSource1" AllowPaging="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" onpageindexchanged="ResGridView_PageIndexChanged"> <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" /> <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /> <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" /> <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" /> <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" /> <AlternatingRowStyle BackColor="#F7F7F7" /> </asp:GridView>
using System;using System.Collections;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;public partial class test_page : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ResGridView.DataBind(); } } protected void QryButton_Click(object sender, EventArgs e) { string strTable = ""; /*set strTable...*/ SqlDataSource1.SelectCommand += "select cus_id from t_temp" + strTable; ResGridView.Visible = true; ResGridView.DataBind(); } protected void ResGridView_PageIndexChanged(object sender, EventArgs e) { ResGridView.DataBind(); }}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; bind();//绑定数据 }
[解决办法]
你这个GridView的数据源是数据源控件吧
哪么你在分页事件里有没有再次绑定数据源ID呢?
[解决办法]
分页后再绑定下数据库!
[解决办法]
lz的方法我有些不明白
我一般在后台绑定的时候都是这么写:ResGridView.DataSource=查询方法(一般返回一个list集合);
ResGridView.DataBind();