首页 新闻 赞助 找找看

为什么我设置gridview分页功能为true后,运行没有分页效果

0
悬赏园豆:10 [已解决问题] 解决于 2011-09-02 16:46

为什么我设置gridview分页功能为true后,运行没有分页效果,每页我设置为10行,可到11行还不分页

问题补充:
1 protected void GridViewBindData()
2 {
3 string SqlString = "select * from books where TypeId="+this.booktypeList.SelectedValue;
4 SqlDataAdapter Myadapter = new SqlDataAdapter(SqlString,con);
5 DataSet ds = new DataSet();
6 Myadapter.Fill(ds,SqlString);
7 this.GridView1.DataSource = ds.Tables[0].DefaultView;
8 this.GridView1.DataMember = SqlString;
9 this.GridView1.DataBind();
10 if(ds.Tables[0].Rows.Count>0)
11 {
12 GridView1.HeaderRow.HorizontalAlign = HorizontalAlign.Center;
13
14 GridView1.Columns[0].ItemStyle.Width = 100;
15 GridView1.Columns[1].ItemStyle.Width = 500;
16
17
18 GridView1.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Center;
19 GridView1.Columns[1].ItemStyle.HorizontalAlign = HorizontalAlign.Center;
20
21 }
22 con.Close();
23
24 }
1 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
2 BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
3 CellPadding="4" EmptyDataText="暂无记录"
4 onpageindexchanging="GridView1_PageIndexChanging">
5 <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
6 <Columns>
7 <asp:TemplateField HeaderText="编号" SortExpression="Id">
8 <ItemTemplate>
9 <asp:Label ID="Label1" runat="server" Text='<%# Bind("Id") %>'></asp:Label>
10 </ItemTemplate>
11 </asp:TemplateField>
12 <asp:TemplateField HeaderText="图书名称" SortExpression="BookName">
13 <ItemTemplate>
14 <asp:Label ID="Label2" runat="server" Text='<%# Bind("BookName") %>'></asp:Label>
15 </ItemTemplate>
16 </asp:TemplateField>
17 <asp:TemplateField HeaderText="销售价格" SortExpression="SalePrice">
18 <ItemTemplate>
19 <asp:Label ID="Label2" runat="server" Text='<%# Bind("SalePrice") %>'></asp:Label>
20 </ItemTemplate>
21 </asp:TemplateField>
22 <asp:TemplateField HeaderText="阅读次数" SortExpression="ReadCount">
23 <ItemTemplate>
24 <asp:Label ID="Label2" runat="server" Text='<%# Bind("ReadCount") %>'></asp:Label>
25 </ItemTemplate>
26 </asp:TemplateField>
27
28 <asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="BookUpdate.aspx?bid={0}"
29 HeaderText="修 改" Text="修 改" />
30 <asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="BookDelete.aspx?bid={0}"
31 HeaderText="删 除" Text="删 除" />
32 </Columns>
33 <RowStyle BackColor="White" ForeColor="#003399" />
34 <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
35 <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
36 <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
37 </asp:GridView>
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex
= e.NewPageIndex;
GridViewBindData();
}


                            
                                
                                    
                          

冷水寒冰的主页 冷水寒冰 | 初学一级 | 园豆:3
提问于:2011-05-18 10:57
< >
分享
最佳答案
0

并不是什么数据源都可以让GridView实现自动分页的,比如如果DataSourceMode是DataReader,就无法实现自动分页。而且只有ObjectDataSource是界面级别的支持分页,类似我们常用的SqlDataSource都是先提取所有的记录,然后只显示本页需要显示的记录,然后抛弃其余的记录,都有点浪费资源的啦!

收获园豆:10
小w威 | 初学一级 |园豆:37 | 2011-05-18 13:19
发了,帮忙看看吧老兄,谢了。
冷水寒冰 | 园豆:3 (初学一级) | 2011-05-19 21:38
其他回答(2)
0

你的数据超过10行嘛?

顾晓北 | 园豆:10844 (专家六级) | 2011-05-18 11:06
当然超过了老兄
支持(0) 反对(0) 冷水寒冰 | 园豆:3 (初学一级) | 2011-05-18 12:03
你取数据的代码发出来。
支持(0) 反对(0) 顾晓北 | 园豆:10844 (专家六级) | 2011-05-18 14:13
发了,帮忙看看吧老兄,谢了。
支持(0) 反对(0) 冷水寒冰 | 园豆:3 (初学一级) | 2011-05-19 21:38
你现在是可以显示前十条,但是下面没分页效果是么?另外,
this.GridView1.DataSource = ds.Tables[0].DefaultView;这一句直接等于ds就行,因为你下面设置了DataMember了,如果是你想这样,应该就不用下面那一句了。。你调试一下看看你查出来的数据有多少行,看看你的ds里面第一个表表明是什么。
支持(0) 反对(0) 顾晓北 | 园豆:10844 (专家六级) | 2011-05-20 10:17
0

把演示工程或代码贴出来。

玛瑙王国--这里的玛瑙会说话 | 园豆:258 (菜鸟二级) | 2011-05-18 11:55
为什么我的代码不能全部显示出来啊?
支持(0) 反对(0) 冷水寒冰 | 园豆:3 (初学一级) | 2011-05-18 12:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册