datalist嵌套时从表无法绑定问题

sayluyun 2009-10-15 05:18:38

<asp:DataList ID="Dlt_Class" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" BorderColor="White" EnableTheming="True" Height="422px" Width="736px">

<ItemTemplate>
<table style="width: 242px; border-right: lime 3px double; border-top: lime 3px double; border-left: lime 3px double; border-bottom: lime 3px double;">
<tr>
<td style="width: 223px; font-weight: bold; font-size: 10pt;" align="center">
<a href="ClassType.aspx?id=<%# Eval("PKID") %>&twoid=<%# Eval("UPID") %>"><%# DataBinder.Eval(Container.DataItem, "ClassName")%></a>
</td>
</tr>
<tr>
<td style="width: 223px; height: 73px;">
<asp:DataList id="childDataList" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'> /////下面的无法绑定
<HeaderTemplate>
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
</HeaderTemplate>
<itemtemplate>
<a href="ClassType.aspx?id=<%# Eval("[\"PKID\"]") %>&twoid=<%# Eval("[\"UPID\"]") %>"><%# DataBinder.Eval(Container.DataItem, "[\"ClassName\"]")%></a>    
</itemtemplate>
<FooterTemplate>
</td>
</tr>
</table>

</FooterTemplate>
</asp:DataList></td>
</tr>

</table>

</ItemTemplate>
<ItemStyle VerticalAlign="Top" />


</asp:DataList>


页面只显示大类的名称 大类下面的子类都无法显示
后台代码

public void Bind()
{
string strSQL,strSQL1, strSQL2;
strSQL1 = "select * from t_sj_ClassInfo where UPID=0 ";
strSQL2 = "select * from t_sj_ClassInfo where UPID<>0 ";
strSQL = strSQL1 + ";" + strSQL2;
DataSet ds = GetDataSet(strSQL);
ds.Relations.Add("myrelation", ds.Tables[0].Columns["PKID"], ds.Tables[1].Columns["PKID"],false);
Dlt_Class.DataSource = ds.Tables[0];
Dlt_Class.DataBind();
}

public static DataSet GetDataSet(string sql)
{

SqlDataAdapter da = null;
DataSet ds = new DataSet();
int i = 1;
string[] strSqls = sql.Split(';');
foreach (string strSql in strSqls)
{
da = GetAdapter(strSql);
da.Fill(ds, "table" + i.ToString());
i++;
}

return ds;

}
public static SqlDataAdapter GetAdapter(string sql)
{
SqlDataAdapter da = new SqlDataAdapter((SqlCommand)GetCommand(sql));
return da;
}
public static IDbCommand GetCommand(string sql)
{
IDbCommand cmd = new SqlCommand(sql, (SqlConnection)GetConnection());
return cmd;
}
public static IDbConnection GetConnection()
{
IDbConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["dbConnStr"]);
return cnn;
}



数据库如下
PKID ClassName UPID code
1 水果 0 0001
2 苹果 1 00010001
3 香蕉 1 00010002
4 家电 0 0002
5 彩电 4 00020001

期待各位的答复
...全文
73 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sayluyun 2009-10-15
  • 打赏
  • 举报
回复
怎么没人解答???
sayluyun 2009-10-15
  • 打赏
  • 举报
回复
期待高手出现啊·····
sayluyun 2009-10-15
  • 打赏
  • 举报
回复
人呢 人呢 ·····
gonghuaqiao 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sayluyun 的回复:]
引用 3 楼 gonghuaqiao 的回复:
C# codepublicvoid Bind()
  {string strSQL,strSQL1, strSQL2;
            strSQL1="select * from t_sj_ClassInfo where UPID=0";
            strSQL2="select * from t_sj_ClassInfo where UPID <>0";
        ¡­


  嵌套在里面的  你能把childDataList直接拿出来绑定??  你试下你写的看能通过不?
[/Quote]
不好意思 看错了 嵌套没用过
sayluyun 2009-10-15
  • 打赏
  • 举报
回复
子datalist有datasource
sayluyun 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 gonghuaqiao 的回复:]
C# codepublicvoid Bind()
{string strSQL,strSQL1, strSQL2;
strSQL1="select * from t_sj_ClassInfo where UPID=0";
strSQL2="select * from t_sj_ClassInfo where UPID<>0";
¡­
[/Quote]

嵌套在里面的 你能把childDataList直接拿出来绑定?? 你试下你写的看能通过不?
gonghuaqiao 2009-10-15
  • 打赏
  • 举报
回复


public void Bind()
{
string strSQL,strSQL1, strSQL2;
strSQL1 = "select * from t_sj_ClassInfo where UPID=0 ";
strSQL2 = "select * from t_sj_ClassInfo where UPID<>0 ";
strSQL = strSQL1 + ";" + strSQL2;
DataSet ds = GetDataSet(strSQL);
Dlt_Class.DataSource = ds.Tables[0];
Dlt_Class.DataBind();
childDataList.DataSource=ds.Tables[1];
childDataList.DataBind();
}

public static DataSet GetDataSet(string sql)
{
DataSet ds = new DataSet();
SqlDataAdapter da = GetAdapter(strSql);
da.Fill(ds);
return ds;
}


comzheng 2009-10-15
  • 打赏
  • 举报
回复
你子datalist的绑定代码呢?
sayluyun 2009-10-15
  • 打赏
  • 举报
回复
沙发 自己坐···

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧