有可能你翻页后的数据不够一页,而你在前一页中选择显示明细的那一项的索引序号大于翻页后的最大索引序号。应该考虑在翻页代码中清除当前选择项。
DataGrid1.SelectedIndex = -1;

解决方案 »

  1.   

    来这里看看,分页大全
    http://www.aspxcn.net
      

  2.   

    你可以试试在DataGrid的ItemDataBound事件里为每一个按钮添加相对应的信息,这样好象分页就不会影响了!我试过一次,成功了!但是还不知道你具体的情况,只能给你说这些!
      

  3.   

    谢谢大家,我看看
    先把我代码发上来<%@ Page Language="C#"%>
    <%@ import Namespace="System.Data"%>
    <%@ import Namespace="System.Data.SqlClient"%><script runat="server">public void Page_Load(Object sender, EventArgs e)
    {// DataGridList.DataSource = ds.Tables["DataGridList"].DefaultView; PanelMemo.Visible = false; BindGrid();
    }
    ICollection CreateDataSource()
    {
    SqlConnection conn = new SqlConnection((string)Application["conn"]); string strSql = "select * from ftp_list order by priority,ip";
    DataSet ds = new DataSet();
    SqlDataAdapter adap = new SqlDataAdapter (strSql,conn);
    adap.Fill(ds,"DataGridList");
    return ds.Tables["DataGridList"].DefaultView;
    }
    void BindGrid()
    {
    DataView dv = (DataView)CreateDataSource();
    DataGridList.VirtualItemCount = dv.Count;
    DataGridList.DataSource = dv;
    DataGridList.DataBind();
    }
    public void ButtonClosePanel_Click(Object sender, EventArgs e)
    {
    PanelMemo.Visible = false;
    }
    public void DataGrid_PageChanged(Object sender, DataGridPageChangedEventArgs e)
    {
    DataGridList.CurrentPageIndex = e.NewPageIndex;
    DataGridList.SelectedIndex = -1;
    BindGrid();
    }public void DataGrid_ItemCommand(Object sender, DataGridCommandEventArgs e)
    {
    TableRow tr = e.Item;
    LabelMemo.Text = tr.Cells[8].Text; PanelMemo.Visible = true;
    }</script><html>
    <head>
    <meta http-equiv=Content-Type content=text/html; charset=gb2312>
    <title>ahduo(阿多)</title>
    <link rel="stylesheet" href="css.css" type="text/css">
    <script>
    if(top.location!=location)
    top.location.href=location.href;
    </script>
    </head><body topmargin="30" background="img/bj.jpg"><form runat="server">
    <asp:DataGrid id="DataGridList" runat="server"  CellPadding="3"
    AutoGenerateColumns="False" BorderColor="#CCCCCC"  Font-Names="Verdana" Font-Size="11px"
    Width="750" Horizontalalign="Center"
    OnItemCommand="DataGrid_ItemCommand"
    OnPageIndexChanged="DataGrid_PageChanged"
    AllowPaging="True" AllowCustomPaging="True"
    PageSize="3"
    PagerStyle-Mode="NumericPages"
    >
    <HeaderStyle horizontalalign="Center" forecolor="White" backcolor="#006699"/>
    <ItemStyle forecolor="#999999" backcolor="#e5f0ff"/>
    <AlternatingItemStyle backcolor="#fcfcfc"/><columns>
    <asp:BoundColumn DataField="name" HeaderText="FTP站点">
    <ItemStyle font-bold="True" forecolor="#2266aa"/>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="ip" HeaderText="IP地址"/>
    <asp:BoundColumn DataField="userl" HeaderText="浏览帐号"/>
    <asp:BoundColumn DataField="pwdl" HeaderText="浏览密码"/>
    <asp:BoundColumn DataField="userd" HeaderText="下载帐号"/>
    <asp:BoundColumn DataField="pwdd" HeaderText="下载密码"/>
    <asp:BoundColumn DataField="isok" HeaderText="状态"><ItemStyle horizontalalign="Center"/></asp:BoundColumn>
    <asp:BoundColumn DataField="note" HeaderText="简介"/>
    <asp:BoundColumn DataField="memo" Visible=false/>
    <asp:ButtonColumn HeaderText="详细" Text="More"><ItemStyle horizontalalign="Center"/></asp:ButtonColumn>
    </columns>
    </asp:DataGrid>
    <asp:Panel id="PanelMemo" runat="server" HorizontalAlign="Center"
    BackColor="#f0f0ff"
    style="position:absolute;top:15%;left:13%"
    ><table cellpadding="0" cellspacing="0" style="border-top:#2266aa 1px solid;border-bottom:#2266aa 1px solid;border-left:#2266aa 1px solid;border-right:#2266aa 1px solid">
    <tr><td>
    <table cellspacing="10"><tr><td>
    <asp:Label id="LabelMemo" runat="server" width="550"/>
    </td></tr></table>
    </td></tr><tr><td align="right" valign=top>
    <asp:Button id="ButtonClosePanel" class="button3" runat="server" Text="关闭" OnClick="ButtonClosePanel_Click"/>
    </td></tr></table></asp:Panel></form>
    </body>
    </html>