首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

gridview 自定义分页在转到某页时无数据,多谢

2011-12-13 
gridview 自定义分页在转到某页时无数据,在线等,谢谢问题:在gotopage中任意选一个数字后,gridview中没有数

gridview 自定义分页在转到某页时无数据,在线等,谢谢
问题:在goto   page   中任意选一个数字后,gridview中没有数据出来.但用first   next   等按钮操作翻页则可以.
代码:listnews.aspx:
<%@   Page   Language= "C# "   AutoEventWireup= "true "   CodeFile= "Listnews.aspx.cs "   Inherits= "Listnews "   %>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   runat= "server ">
        <title> 无标题页 </title>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
                        <asp:GridView   ID= "gvNewsLists "   runat= "server "   AllowPaging= "True "   AllowSorting= "True "
                        AutoGenerateColumns= "False "   CellPadding= "4 "   ForeColor= "#333333 "   GridLines= "None "
                        Width= "100% "   DataKeyNames= "newsid "   OnPageIndexChanging= "gvNewsLists_PageIndexChanging "   OnRowEditing= "gvNewsLists_RowEditing "   OnRowUpdating= "gvNewsLists_RowUpdating "   OnSorting= "gvNewsLists_Sorting "   PageSize= "20 "   OnRowCancelingEdit= "gvNewsLists_RowCancelingEdit "   OnRowCommand= "gvNewsLists_RowCommand "   OnRowCreated= "GridView1_RowCreated ">
                        <FooterStyle   BackColor= "#990000 "   Font-Bold= "True "   ForeColor= "White "   />
                        <Columns>
                                <asp:BoundField   DataField= "newsid "   HeaderText= "news   id "   ReadOnly= "True "   />
                                <asp:BoundField   DataField= "topic "   HeaderText= "topic "   SortExpression= "topic "   />
                                <asp:BoundField   DataField= "ntime "   HeaderText= "ntime "   SortExpression= "ntime "   />
                                <asp:ButtonField   Text= "Delete "   ButtonType= "Button "   CommandName= "Delete "   />
                                <asp:ButtonField   Text= "Edit "   ButtonType= "Button "   CommandName= "Edit "   />
                        </Columns>
                        <PagerTemplate> Goto   Page  


<asp:DropDownList   ID= "ddlPageSelector "   runat= "server "   AutoPostBack= "true "> </asp:DropDownList>

        <asp:Button   Text= "First "   CommandName= "Page "   CommandArgument= "First "   runat= "server "

                ID= "btnFirst "   />

        <asp:Button   Text= "Previous "   CommandName= "Page "   CommandArgument= "Prev "   runat= "server "

                ID= "btnPrevious "   />

        <asp:Button   Text= "Next "   CommandName= "Page "   CommandArgument= "Next "   runat= "server "

                ID= "btnNext "   />

        <asp:Button   Text= "Last "   CommandName= "Page "   CommandArgument= "Last "   runat= "server "

                ID= "btnLast "   />

</PagerTemplate>  
                        <RowStyle   BackColor= "#FFFBD6 "   ForeColor= "#333333 "   />
                        <SelectedRowStyle   BackColor= "#FFCC66 "   Font-Bold= "True "   ForeColor= "Navy "   />
                        <PagerStyle   BackColor= "#FFCC66 "   ForeColor= "#333333 "   HorizontalAlign= "Center "   />
                        <HeaderStyle   BackColor= "#990000 "   Font-Bold= "True "   ForeColor= "White "   />
                        <AlternatingRowStyle   BackColor= "White "   />

                </asp:GridView>
        </div>
        </form>
</body>
</html>


[解决办法]
gridView.PageIndex = ddlPageSelector.SelectedIndex; gridView.DataBind();==> gridView.PageIndex = ddlPageSelector.SelectedIndex; BindGrid();这里
[解决办法]
楼上两位正解,楼上的还需要再写代码,幕白兄的不用再写代码了.
[解决办法]
把 ddlPageSelector.SelectedIndexChanged 移到页面中处理

热点排行