问题描述
我想用gridview做子页导航,页面里放置隐藏的panel控件,每个pannel里分别有一个gridview用来绑定新闻数据。但是怎么实现点击Gridview中不同的链接跳转到同一个页面的不同控件呢?意思就是说点击导航里任意一个分类的时候,怎么显示相应的panel?1、做子页导航的gridview的DataNavigateUrlFormatString那里该怎么写?或者用后台代码怎么实现?2、e.NewPageIndex下划了红线,是哪里缺少了什么代码?代码如下,新手,不会用后台代码实现,希望得到大神们详细具体的指点,蟹蟹~<div><asp:GridViewID="gvnav"runat="server"AllowSorting="True"AutoGenerateColumns="False"CellPadding="0"Style="margin-top:0px"Width="116px"OnSelectedIndexChanged="gvnav_SelectedIndexChanged"GridLines="None"ShowHeader="False"PageSize="7"><Columns><asp:HyperLinkFieldDataNavigateUrlFields="ID"DataNavigateUrlFormatString="bmdt.aspx?id={0}"DataTextField="ColumnName"HeaderText="新闻类型"/></Columns></asp:GridView><h3><asp:LabelID="labTitle"runat="server"></asp:Label></h3><asp:PanelID="panZXGG"runat="server"Visible="false"><asp:GridViewID="gvZXGG"runat="server"AllowPaging="True"AllowSorting="True"AutoGenerateColumns="False"CellPadding="0"HorizontalAlign="Center"Style="margin-top:0px"Width="560px"GridLines="None"OnSelectedIndexChanged="gvZXGG_SelectedIndexChanged"><Columns><asp:HyperLinkFieldDataNavigateUrlFields="NewsID"DataNavigateUrlFormatString="Article.aspx?id={0}"DataTextField="NewsTitle"HeaderText="标题"Target="_blank"/><asp:BoundFieldDataField="NewsSubmitTime"HeaderText="日期"><HeaderStyleWidth="100px"/></asp:BoundField></Columns></asp:GridView></asp:Panel><asp:PanelID="panRSDT"runat="server"Visible="false"><asp:GridViewID="gvRSDT"runat="server"AllowPaging="True"AllowSorting="True"AutoGenerateColumns="False"CellPadding="0"GridLines="None"HorizontalAlign="Center"OnSelectedIndexChanged="gvzxgg_SelectedIndexChanged"Style="margin-top:0px"Width="560px"><Columns><asp:HyperLinkFieldDataNavigateUrlFields="NewsID"DataNavigateUrlFormatString="Article.aspx?id={0}"DataTextField="NewsTitle"HeaderText="标题"Target="_blank"/><asp:BoundFieldDataField="NewsSubmitTime"HeaderText="日期"><HeaderStyleWidth="100px"/></asp:BoundField></Columns></asp:GridView></asp:Panel></div>usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Web.Security;usingSystem.Xml.Linq;usingSystem.Web.UI.HtmlControls;usingSystem.Web.UI.WebControls.WebParts;publicpartialclassbmdt:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){stringsqlstr="selecttop7ID,ColumnNamefromtb_Columnwherelen(ID)=2andIDlike'1%'orderbyIDasc";DataTabledt=WebFunction.dataTable(sqlstr);gvnav.DataSource=dt;gvnav.DataBind();}protectedvoidsetPanelVisible(stringtitle){labTitle.Text=title;panZXGG.Visible=false;panRSDT.Visible=false;}protectedvoidGridViewBind(GridViewgvStr,stringcolStr,stringtableStr,stringwhereStr,stringorderStr){stringsqlstr="select"+colStr+"from"+tableStr+whereStr+orderStr;DataTabledt=WebFunction.dataTable(sqlstr);gvStr.DataSource=dt;gvStr.DataBind();}protectedvoidgvnav_SelectedIndexChanged(objectsender,EventArgse){}/*setPanelVisible("当前页面:部门动态——>最新公告");panZXGG.Visible=true;GridViewBind(gvZXGG,"NewsID,NewsTitle","tb_News","","TypeID='zxgg'orderbyNewsIDdesc");setPanelVisible("当前页面:部门动态——>人事动态");panRSDT.Visible=true;GridViewBind(gvRSDT,"NewsID,NewsTitle","tb_News","","TypeID='rsdt'orderbyNewsIDdesc");*/protectedvoidgvZXGG_SelectedIndexChanged(objectsender,EventArgse){gvZXGG.PageIndex=e.NewPageIndex;gvZXGG.DataBind();}protectedvoidgvzxgg_SelectedIndexChanged(objectsender,EventArgse){gvRSDT.PageIndex=e.NewPageIndex;gvRSDT.DataBind();}}