DataGrid用了模板列以后分页急问 有可能你翻页后的数据不够一页,而你在前一页中选择显示明细的那一项的索引序号大于翻页后的最大索引序号。应该考虑在翻页代码中清除当前选择项。DataGrid1.SelectedIndex = -1; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 来这里看看,分页大全http://www.aspxcn.net 你可以试试在DataGrid的ItemDataBound事件里为每一个按钮添加相对应的信息,这样好象分页就不会影响了!我试过一次,成功了!但是还不知道你具体的情况,只能给你说这些! 谢谢大家,我看看先把我代码发上来<%@ 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> C#关于日期的问题 存储过程如何参数化sql语句??? 数据库int类型字段在条件语句里如何表达所有? 红外报警壳的问题 初学.net,简单问题请教 求页页级"变量"处理方法 如何使一个控件位于页面的正中间? 初学者:提问?马上就结分 请问哪里有《.net教学案例-商务解决方案》下载? 为何我用DataGrid组件的分页功能,却不能分页呢。 请各位帮帮吗。 如何在ASP.NET中连接PROGRESS数据库?
http://www.aspxcn.net
先把我代码发上来<%@ 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>