问题描述
我使用gridview显示资源列表,然后资源可按类别查询,如课件、视频等,然后查询我是通过改变datasource的selectcommand来实现的,当页面加载时,gridview显示所有类型的资源名称,如点击视频按钮后,则显示视频类型的资源,但在分页时,又重新绑定了全部类型的资源,查了好多分页的模板,我也不太会用,试了都不行,急求帮助!这是前台<tableid="search"width="730px"><tr><tdwidth="100px"height="35px"><spanstyle="font-size:20px">关键词:</span></td><tdalign="left"width="150px"height="35px"><asp:TextBoxID="TextBox1"runat="server"Height="25px"></asp:TextBox></td><tdalign="left"height="35px"><asp:ImageButtonID="ImageButton1"runat="server"ImageUrl="img/qb.png"onclick="ImageButton1_Click"/></td></tr><tr><tdcolspan="3"height="35px"><span><asp:ImageButtonID="ImageButton2"runat="server"ImageUrl="img/kj.png"onclick="ImageButton2_Click"/><asp:ImageButtonID="ImageButton3"runat="server"ImageUrl="img/sp.png"onclick="ImageButton3_Click"/><asp:ImageButtonID="ImageButton4"runat="server"ImageUrl="img/wb.png"onclick="ImageButton4_Click"/><asp:ImageButtonID="ImageButton5"runat="server"ImageUrl="img/yp.png"onclick="ImageButton5_Click"/><asp:ImageButtonID="ImageButton6"runat="server"ImageUrl="img/al.png"onclick="ImageButton6_Click"/><asp:ImageButtonID="ImageButton7"runat="server"ImageUrl="img/dh.png"onclick="ImageButton7_Click"/></span></td></tr></table><tablewidth="730px"id="xiangxi"><tr><td><asp:GridViewID="GridView1"runat="server"AllowPaging="True"AutoGenerateColumns="False"DataKeyNames="R_NAME"DataSourceID="AccessDataSource1"Width="730px"EmptyDataText="暂无相关资源"ShowHeader="false"GridLines="None"onrowdatabound="GridView1_RowDataBound"onpageindexchanging="GridView1_PageIndexChanging"PageSize="2"><Columns><asp:HyperLinkFieldControlStyle-CssClass="link"DataTextField="R_NAME"DataNavigateUrlFields="R_ID"DataNavigateUrlFormatString="~/TJ.aspx?R_ID={0}"Target="_blank"/></Columns></asp:GridView><asp:AccessDataSourceID="AccessDataSource1"runat="server"DataFile="~/App_Data/jxzygxpt.mdb"SelectCommand="SELECT*FROM[T_RESOURCE]WHERE[R_MAJOR]='信息管理与信息系统'AND[R_STATUS]=-1orderby[R_WEEKHITS]desc"></asp:AccessDataSource></td></tr></table>
这是后台protectedvoidImageButton1_Click(objectsender,ImageClickEventArgse){AccessDataSource1.SelectCommand="SELECT*FROM[T_RESOURCE]WHERE[R_MAJOR]='信息管理与信息系统'AND[R_STATUS]=-1AND([R_KEY]LIKE'%"+TextBox1.Text+"%'OR[R_NAME]LIKE'%"+TextBox1.Text+"%')orderby[R_WEEKHITS]desc";}protectedvoidImageButton2_Click(objectsender,ImageClickEventArgse){AccessDataSource1.SelectCommand="SELECT*FROM[T_RESOURCE]WHERE[R_MAJOR]='信息管理与信息系统'AND[R_STATUS]=-1AND[R_TYPE]='课件(PPT)'AND([R_KEY]LIKE'%"+TextBox1.Text+"%'OR[R_NAME]LIKE'%"+TextBox1.Text+"%')orderby[R_WEEKHITS]desc";}protectedvoidImageButton3_Click(objectsender,ImageClickEventArgse){AccessDataSource1.SelectCommand="SELECT*FROM[T_RESOURCE]WHERE[R_MAJOR]='信息管理与信息系统'AND[R_STATUS]=-1AND[R_TYPE]='视频素材'AND([R_KEY]LIKE'%"+TextBox1.Text+"%'OR[R_NAME]LIKE'%"+TextBox1.Text+"%')orderby[R_WEEKHITS]desc";}protectedvoidImageButton4_Click(objectsender,ImageClickEventArgse){AccessDataSource1.SelectCommand="SELECT*FROM[T_RESOURCE]WHERE[R_MAJOR]='信息管理与信息系统'AND[R_STATUS]=-1AND[R_TYPE]='文本素材'AND([R_KEY]LIKE'%"+TextBox1.Text+"%'OR[R_NAME]LIKE'%"+TextBox1.Text+"%')orderby[R_WEEKHITS]desc";}protectedvoidImageButton5_Click(objectsender,ImageClickEventArgse){AccessDataSource1.SelectCommand="SELECT*FROM[T_RESOURCE]WHERE[R_MAJOR]='信息管理与信息系统'AND[R_STATUS]=-1AND[R_TYPE]='音频素材'AND([R_KEY]LIKE'%"+TextBox1.Text+"%'OR[R_NAME]LIKE'%"+TextBox1.Text+"%')orderby[R_WEEKHITS]desc";}protectedvoidImageButton6_Click(objectsender,ImageClickEventArgse){AccessDataSource1.SelectCommand="SELECT*FROM[T_RESOURCE]WHERE[R_MAJOR]='信息管理与信息系统'AND[R_STATUS]=-1AND[R_TYPE]='案例'AND([R_KEY]LIKE'%"+TextBox1.Text+"%'OR[R_NAME]LIKE'%"+TextBox1.Text+"%')orderby[R_WEEKHITS]desc";}protectedvoidImageButton7_Click(objectsender,ImageClickEventArgse){AccessDataSource1.SelectCommand="SELECT*FROM[T_RESOURCE]WHERE[R_MAJOR]='信息管理与信息系统'AND[R_STATUS]=-1AND[R_TYPE]='动画素材'AND([R_KEY]LIKE'%"+TextBox1.Text+"%'OR[R_NAME]LIKE'%"+TextBox1.Text+"%')orderby[R_WEEKHITS]desc";}//publicstaticintflag=1;protectedvoidGridView1_PageIndexChanging(objectsender,GridViewPageEventArgse){GridView1.PageIndex=e.NewPageIndex;//获取当前分页的索引值GridView1.DataBind();//重新绑定数据}
解决方案
解决方案二:
分页就是分段查询,不一次性查出来
解决方案三:
引用1楼FoxDave的回复:
分页就是分段查询,不一次性查出来
那想要正常分页怎么办啊,不能用改datasource的command了吗
解决方案四:
没人吗