标题:[求助]DataGrid分页后,点击索引后无法显示表!
取消只看楼主
powerPHP
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-12-15
 问题点数:0 回复次数:1 
[求助]DataGrid分页后,点击索引后无法显示表!

问题:
以下代码能让用户通过点击LinkButton自由选看任何一个分页!但分页显示后,点击索引会导致
整个datagrid表都消失!已经设定了OnPageIndexChanged
方法但还是这样,应该怎么改才行?

<%@Import namespace="System.Data" %>
<%@Import namespace="System.Data.SqlClient"%>
<html>
<head>
<title>要分页显示</title>
</head>
<body>
<center>
<form id="form1" runat="server" method="post">
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="data1">LinkButton1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="data2">LinkButton2</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="data3">LinkButton3</asp:LinkButton>
<asp:DataGrid AllowPaging="true" ID="DataGrid1" PageSize="5" runat="server" ShowFooter="false" ShowHeader="true" OnPageIndexChanged="onindex" Height="213px" Width="582px">
<pagerstyle Mode="NumericPages" PageButtonCount="5" />
</asp:DataGrid>
</form>
</center>
</body>
</html>
<script language="C#" runat="server">

void onindex(Object sender, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind( );
}
//------------------------------------
void data1(Object sender, EventArgs e)
{
SqlConnection SqlConnection1 = new SqlConnection("Server=Localhost;user id=sa;password=;database=database1;");
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter("select * from table1", SqlConnection1);
DataSet DataSet1 = new DataSet();
SqlConnection1.Open();
SqlDataAdapter1.Fill(DataSet1);
SqlConnection1.Close();
DataGrid1.DataSource = DataSet1;
DataGrid1.DataBind();

}
void data2(Object sender, EventArgs e)
{
SqlConnection SqlConnection1 = new SqlConnection("Server=Localhost;user id=sa;password=;database=database1;");
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter("select * from table2", SqlConnection1);
DataSet DataSet1 = new DataSet();
SqlConnection1.Open();
SqlDataAdapter1.Fill(DataSet1);
SqlConnection1.Close();
DataGrid1.DataSource = DataSet1;
DataGrid1.DataBind();
}
void data3(Object sender, EventArgs e)
{
SqlConnection SqlConnection1 = new SqlConnection("Server=Localhost;user id=sa;password=;database=database1;");
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter("select * from table3", SqlConnection1);
DataSet DataSet1 = new DataSet();
SqlConnection1.Open();
SqlDataAdapter1.Fill(DataSet1);
SqlConnection1.Close();
DataGrid1.DataSource = DataSet1;
DataGrid1.DataBind();
}
</script>

搜索更多相关主题的帖子: 索引 DataGrid 
2007-05-08 13:04
powerPHP
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-12-15
得分:0 
没人回复吗?

自己先顶一下!还是我的方法太苯!给点思路也行!

矢量的伟大!
2007-05-08 13:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-137622-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.591826 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved