其实很简单的,你应该就是看不懂DataSource='<%# GetDetails(Eval("PKID").ToString()) %>‘这段代码而已,后台很简单
public void types()
{
string Id = Request.QueryString["id"];
string sql = "select PKID,type from foodtype where SjId='" + Id + "'";
SqlCommand com = new SqlCommand(sql, con);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
datalist2.DataSource = ds.Tables[0].DefaultView;
datalist2.DataKeyField = "PKID";
datalist2.DataBind();
}
protected DataTable GetDetails(string PKID)
{
SqlDataAdapter da = new SqlDataAdapter("select PKID,Cy_Name, Age from Cp_Name where Cytype = @PKID", con);
da.SelectCommand.Parameters.AddWithValue("@PKID", PKID);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds);
con.Close();
return ds.Tables[0];
if (IsCipan.Value.ToString() == "False")
{
DataList2.Enabled = false;
TextLinkCipian.Visible = false;
}
else
{
pictureLink.Visible = false;
TextLink.Visible = false;
string cipianSstr = "select * from cipian where idno in(select min(idno) from cipian where isdisplay=1 AND sortID < 5 and productid=@productid group by sortid ) order by sortid asc";
//Response.Write("select * from cipian where idno in(select min(idno) from cipian where isdisplay=1 AND sortID < 5 and productid='" + productid.Value.ToString() + "' group by sortid ) order by sortid asc <br >");
string[] sname = new string[] { "productid" };
string[] sval = new string[] { productid.Value.ToString() };
DbClass cipandb = new DbClass();
DataList2.DataSource = cipandb.ReturnParameterDataReader(cipianSstr, sname, sval);
DataList2.DataBind();
}
后台的代码