后台代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
//行业分类(磁性材料)
conn.Open();
OleDbCommand cmd=new OleDbCommand("select * from SMT_ypxxone where smt_flid=1 order by SMT_date desc",conn);
OleDbDataAdapter mydr = new OleDbDataAdapter(cmd);
DataSet mydt = new DataSet();
mydt.EnforceConstraints = false;
mydr.Fill(mydt, "SMT_ypxxone");
//这里要 定义ID但是不知道怎么写
string ID = DataList9.DataKeys[e.ToString //这里如何写各位大狭看看
OleDbCommand cmd1=new OleDbCommand("select top 6 * from SMT_ypxxtwo where SMT_ypxxone_id=" + ID + " order by SMT_date desc",conn);
OleDbDataAdapter mydr1 = new OleDbDataAdapter(cmd1);
mydr1.Fill(mydt, "SMT_ypxxtwo");
mydt.Relations.Add("myrelations", mydt.Tables["SMT_ypxxone"].Columns["SMT_ypxxone_id"], mydt.Tables["SMT_ypxxtwo"].Columns["SMT_ypxxone_id"]);
DataList9.DataSource = mydt.Tables["SMT_ypxxone"].DefaultView;
DataList9.DataBind();
前台代码
<asp:DataList ID="DataList9" runat="server" RepeatColumns="2" DataKeyField="SMT_ypxxone_id" Width="400" >
<ItemTemplate>
<span style=" color:Gray"><%# Eval("SMT_ypxxone")%></span><br />
<asp:DataList ID="DataList14" runat="server" RepeatColumns="3" DataSource='<%# Eval("myrelations")%>' >
<ItemTemplate>
<%# Eval("SMT_ypxxtwo")%>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>