GridView控件的分页显示问题
使用DropDownList选择其中任意一项,将查询结果返回到GridView中显示,GridView启用了分页效果,问题是,当点击GridView中任意一个分页链接时,显示的是全部结果,之前筛选出来的结果被冲掉了.我想实现的效果是当安闲DropDownList选择其中某项时,筛选出来的结果显示在GridView中,即使翻页也不会影响当前结果.如何实现?以下是我写的源码:
显示页面--
<body>
<form id="form1" runat="server">
<table width="800" border="1" cellspacing="0" cellpadding="0">
<tr>
<td class="style1">
<asp:DropDownList ID="Drp1" runat="server" DataSourceID="DrpAcc" DataTextField="dz"
DataValueField="dz" OnSelectedIndexChanged="sec" AutoPostBack="True">
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="Dp2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rqshow">
<asp:ListItem>2008-4-28</asp:ListItem>
<asp:ListItem>2008-4-29</asp:ListItem>
<asp:ListItem>2008-4-30</asp:ListItem>
<asp:ListItem>2008-5-1</asp:ListItem>
<asp:ListItem>2008-5-2</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" CellPadding="4" DataSourceID="Acc1"
ForeColor="#333333" GridLines="None" PageSize="50">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
</table>
<asp:AccessDataSource ID="Acc1" runat="server" DataFile="~/tjbase/IPTJ.mdb" SelectCommand="SELECT * FROM [accIP]">
</asp:AccessDataSource>
<asp:AccessDataSource ID="DrpAcc" runat="server" DataFile="~/tjbase/IPTJ.mdb" SelectCommand="SELECT DISTINCT [dz] FROM [accIP] where dz <> ''">
</asp:AccessDataSource>
</form>
</body>
控制页面代码:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void sec(object sender, EventArgs e)
{
string t = Drp1.SelectedValue;
if (t.Equals("All"))
Acc1.SelectCommand = "SELECT * FROM [accIP] ";
else
Acc1.SelectCommand = "SELECT * FROM [accIP] where dz='" + t + "'";
}
private void Tzh()
{
string myConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " + Server.MapPath("~/") + "tjbase/IPTJ.mdb"; //使用相对路径连接数据库
string mySelectQuery = "select DISTINCT Tdate from accIP ";//查询语句
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
myConnection.Open();
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while (myReader.Read())
{
Response.Write(myReader.GetDateTime(0));
Response.Write("<br>");
}
myReader.Close();
}
protected void rqshow(object sender, EventArgs e)
{
string rq=Dp2.SelectedValue;
string tt = rq.Substring(0, 9);
Acc1.SelectCommand = "SELECT * FROM [accIP] where Tdate like'%"+tt+"%'";
} --------------------编程问答-------------------- --------------------编程问答-------------------- does the DataReader support paging? try DataSet or other --------------------编程问答-------------------- 高手进来看看呢,咋没人回答啊! --------------------编程问答-------------------- 学习中,一起等待!! --------------------编程问答-------------------- 你的这些代码很不规范
比如说你就是在UI层直接访问SQL层,这样写.怎么说呢.行倒是行就是这样写总感觉不好
SQL语句.关键词应该大写.你的有些大写有些又小写
还有你的命名.全是些魔鬼命名 如string t = Drp1.SelectedValue;
你的问题我理解的是:比如第一个条件是查15条出来.第一页显示10条后,第二页应该只显示5条.但是你一翻页又显示的是全部信息的第二页对吗?
只能说你的分页有问题.在翻第二页时应该把条件和页数继续传过去.
分页现在太多了,也不知道你是自己写的存储过程还是什么.
补充:.NET技术 , ASP.NET