.net datalist 嵌套问题
前台代码<div><asp:DataListID="DataList1"runat="server"OnItemDataBound="DataList1_DataBind...
前台代码
<div>
<asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_DataBinding">
<ItemTemplate>
<asp:Label runat="server" ID="L" Text='<%#DataBinder.Eval(Container.DataItem,"id") %>'></asp:Label>
<%#DataBinder.Eval(Container.DataItem,"id") %>
<br />
<asp:DataList runat="server" ID="DataList2">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"id") %>
<br />
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
</div>
后台代码
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = db.crconn();
conn.Open();
//SqlCommand cmd = new SqlCommand("select * from InClass", conn);
SqlDataAdapter cmd = new SqlDataAdapter("select * from InClass", conn);
DataSet rs = new DataSet();
cmd.Fill(rs, "inclass");
DataList1.DataSource = rs.Tables["inclass"];
DataList1.DataBind();
conn.Close();
}
protected void DataList1_DataBinding(object sender, DataListItemEventArgs e)
{
DataList dl = (DataList)e.Item.FindControl("DataList2");
Label l = (Label)e.Item.FindControl("L");
SqlConnection conn = db.crconn();
conn.Open();
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from company where InClassId=" + l, conn);
DataSet ds = new DataSet();
cmd1.Fill(ds, "CC");
dl.DataSource = ds;
dl.DataBind();
conn.Close();
}
数据库
inclass 字段 id inclassName
company 字段 id inclassId companyNameCn
想按照inclass 分类输出 公司名称companyNameCn
运行总是提示cmd1.Fill(ds, "CC");
错误 请大家帮忙
如运行成功请给与一个简单的解释!.net新手 展开
<div>
<asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_DataBinding">
<ItemTemplate>
<asp:Label runat="server" ID="L" Text='<%#DataBinder.Eval(Container.DataItem,"id") %>'></asp:Label>
<%#DataBinder.Eval(Container.DataItem,"id") %>
<br />
<asp:DataList runat="server" ID="DataList2">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"id") %>
<br />
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
</div>
后台代码
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = db.crconn();
conn.Open();
//SqlCommand cmd = new SqlCommand("select * from InClass", conn);
SqlDataAdapter cmd = new SqlDataAdapter("select * from InClass", conn);
DataSet rs = new DataSet();
cmd.Fill(rs, "inclass");
DataList1.DataSource = rs.Tables["inclass"];
DataList1.DataBind();
conn.Close();
}
protected void DataList1_DataBinding(object sender, DataListItemEventArgs e)
{
DataList dl = (DataList)e.Item.FindControl("DataList2");
Label l = (Label)e.Item.FindControl("L");
SqlConnection conn = db.crconn();
conn.Open();
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from company where InClassId=" + l, conn);
DataSet ds = new DataSet();
cmd1.Fill(ds, "CC");
dl.DataSource = ds;
dl.DataBind();
conn.Close();
}
数据库
inclass 字段 id inclassName
company 字段 id inclassId companyNameCn
想按照inclass 分类输出 公司名称companyNameCn
运行总是提示cmd1.Fill(ds, "CC");
错误 请大家帮忙
如运行成功请给与一个简单的解释!.net新手 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询