gridview 分页问题,成功分页了,为什么点击第x页时显示空白?
gridview代码:<asp:GridViewID="GridView2"runat="server"CellPadding="4"ForeColor="#333333...
gridview 代码:
<asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AllowPaging="True" PageSize="20" onpageindexchanging="GridView2_PageIndexChanging">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
GridView2_PageIndexChanging()方法:
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e) {
//GridView2.PageIndex = e.NewPageIndex;
//GridView2.DataBind();//重新绑定一遍数据
(sender as GridView).PageIndex = e.NewPageIndex; //指定GridView新页索引 (sender as GridView).DataBind(); //GridView数据源绑定
}
前面用到的填充代码:
if (DropDownList1.Text != "All" && DropDownList2.Text != "All" && DropDownList3.Text != "All")
{
x.sql = "select * from 一次通过率 where 院系名称 = '" + DropDownList2.Text + " ' and 考试时间 = '" + DropDownList3.Text + " 'and 年级 = '" + DropDownList1.Text + " '";
SqlDataAdapter da2 = new SqlDataAdapter(x.sql, x.conn);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "set2");
GridView2.DataSource = ds2.Tables["set2"];
GridView2.DataBind();
} 展开
<asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AllowPaging="True" PageSize="20" onpageindexchanging="GridView2_PageIndexChanging">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
GridView2_PageIndexChanging()方法:
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e) {
//GridView2.PageIndex = e.NewPageIndex;
//GridView2.DataBind();//重新绑定一遍数据
(sender as GridView).PageIndex = e.NewPageIndex; //指定GridView新页索引 (sender as GridView).DataBind(); //GridView数据源绑定
}
前面用到的填充代码:
if (DropDownList1.Text != "All" && DropDownList2.Text != "All" && DropDownList3.Text != "All")
{
x.sql = "select * from 一次通过率 where 院系名称 = '" + DropDownList2.Text + " ' and 考试时间 = '" + DropDownList3.Text + " 'and 年级 = '" + DropDownList1.Text + " '";
SqlDataAdapter da2 = new SqlDataAdapter(x.sql, x.conn);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "set2");
GridView2.DataSource = ds2.Tables["set2"];
GridView2.DataBind();
} 展开
6个回答
展开全部
翻页以后 需要重新绑定GRIDVIEW的,首先你要搞清楚翻页的原理:先查询出符合条件的数据,然后通过TEMPTABLE的自生成ID(此ID自增),查询 从多少条 到多少条的数据。
GRIDVIEW的绑定方法如下:
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = 你通过多少条到多少条查询出来的数据来源列表;
GridView1.DataBind();
GRIDVIEW的绑定方法如下:
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = 你通过多少条到多少条查询出来的数据来源列表;
GridView1.DataBind();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个你还是采用调试的方式处理,在查询数据处设置断点,在分页改变事件中设置断点,查看数据是不是都查出来了,还有就是查看分页的页码和数据是不是都查询出来了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
翻页没重新绑定数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e) {
this.GridView2.PageIndex = e.NewPageIndex;
this.GridView2.DataSource = 数据源;
this.GridView2.DataBind();
}
this.GridView2.PageIndex = e.NewPageIndex;
this.GridView2.DataSource = 数据源;
this.GridView2.DataBind();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
重新读取一次数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询