日期:2014-05-18  浏览次数:20378 次

GridView控件的问题。。。

GridView控件的问题。。。



文章发布系统——》后台管理——》管理文章页面:

用GridView控件显示所有的文章列表,其中有一列是栏目,问题就出在这里

栏目列显示的是数据库里面的单独的表wyx_class的wyx_classname列

文章表是wyx_text(wyx_text表中列wyx_classtype对应wyx_class表中的列wyx_id)

请问如何在GridView栏目列里显示出每篇文章所对应的栏目名称???







前台代码:


  <table align="center" border="1" bordercolor="#666666" cellpadding="0" cellspacing="0"
  width="600">
  <tr>
  <td colspan="2" style="width: 602px; height: 21px; text-align: center">
  <strong><span style="font-size: 16pt">管理文章</span></strong></td>
  </tr>
  <tr>
  <td style="width: 50px; height: 21px;text-align:center">
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="599px" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
  <Columns>
  <asp:BoundField DataField="wyx_id" HeaderText="编号" />
  <asp:BoundField HeaderText="栏目" DataField="wyx_classtype" />
  <asp:HyperLinkField DataNavigateUrlFields="wyx_id" DataNavigateUrlFormatString="../view.aspx?id={0}"
  DataTextField="wyx_title" DataTextFormatString="{0}" HeaderText="标题" Text="标题" >
  <ItemStyle HorizontalAlign="Left" />
  </asp:HyperLinkField>
  <asp:BoundField DataField="wyx_date" HeaderText="日期" />
  <asp:HyperLinkField DataNavigateUrlFields="wyx_id" DataNavigateUrlFormatString="admin_edit.aspx?id={0}"
  HeaderText="编辑" Text="编辑" />
  <asp:HyperLinkField DataNavigateUrlFields="wyx_id" DataNavigateUrlFormatString="admin_del.aspx?id={0}"
  HeaderText="删除" Text="删除" />
  </Columns>
  </asp:GridView>
  <br />
  &nbsp;</td>
  </tr>
  </table>



后台代码:

  protected void Page_Load(object sender, EventArgs e)
  {
  string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../data/wyx.mdb");
  OleDbConnection ConnAcc = new OleDbConnection(strConn); 
  ConnAcc.Open();
  string strSQL = "select * from wyx_text ORDER BY wyx_id DESC";  
  OleDbDataAdapter da = new OleDbDataAdapter(strSQL, ConnAcc); 
  DataSet ds = new DataSet();
  da.Fill(ds, "wyx");
  ConnAcc.Close();
  GridView1.DataSource = ds;
  GridView1.DataBind();
  }


------解决方案--------------------
这个直接考虑构造sql语句,也就是表连接就可以了吧

select a.