Repeater嵌套问题

Gomes 2011-11-12 02:41:35
aspx代码
<div>
<dl>
<asp:Repeater ID="repLevOne" runat="server">
<ItemTemplate>
<dt><%# DataBinder.Eval(Container, "DataItem.name").ToString()%></dt>
<asp:Repeater ID="repLevTwo" runat="server">
<ItemTemplate>
<dd><%# DataBinder.Eval(Container, "DataItem.name").ToString()%></dd>
<dd>
<asp:Repeater ID="repLevThree" runat="server">
<ItemTemplate>
<span><%# DataBinder.Eval(Container, "DataItem.name").ToString()%></span>
</ItemTemplate>
</asp:Repeater>
</dd>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</dl>
</div>

.cs代码
database dbObj = new database();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BdingLev();
}
public void BdingLev()
{
string sqlstrOne = "select id, name, ParentID, typelevel from tb_LevCat where typelevel = 1 and ParentID = 0 and name is not null order by id asc";
string sqlstrTwo = "select id, name, ParentID, typelevel from tb_LevCat where typelevel = 2 and ParentID in (select id from Categories where typelevel =1 and ParentID =0 and name is not null) and name is not null order by id asc";
string sqlstrThree = "select id, name, ParentID, typelevel from tb_LevCat where typelevel = 3 and ParentID in (select id from Categories where typelevel= 2 and name is not null) and name is not null order by id asc";

DataSet ds = new DataSet("Data");
SqlConnection con = dbObj.Getconnection(); //数据库连接,写好的类
SqlCommand cmd = new SqlCommand(sqlstrOne, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
cmd.Connection.Open();
da.Fill(ds, "One");

SqlDataAdapter da2 = new SqlDataAdapter(sqlstrTwo, con);
da2.Fill(ds, "Two");

SqlDataAdapter da3 = new SqlDataAdapter(sqlstrThree, con);
da3.Fill(ds, "Three");

ds.Relations.Add("smallFun", ds.Tables["One"].Columns["id"], ds.Tables["Two"].Columns["ParentID"]);
ds.Relations.Add("small2Fun", ds.Tables["Two"].Columns["id"], ds.Tables["Three"].Columns["ParentID"]);

repLevOne.DataSource = ds.Tables["One"].DefaultView;
repLevOne.DataBind();
cmd.Connection.Close();
}



是一个目录的三级,但是为什么只能显示出一级目录,二级三级的都无法显示
...全文
98 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿非 2011-11-14
  • 打赏
  • 举报
回复
机器人 2011-11-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sandy945 的回复:]

不是DataBind的问题,是你里层的repeater 没有指定 DataSource 导致

08年的时候写过例子,不过帖子忘了.

CSDN现在搜索不给力 只能google

google sandy945 repeater嵌套 Relations

DataBind ->父控件会遍历调用子控件
[/Quote]

掩面奔
Gomes 2011-11-12
  • 打赏
  • 举报
回复
上面的问题我已经解决
<asp:Repeater ID="repLevTwo" runat="server" DataSource='<%# DataBinder.Eval(Container, "DataItem.smallFun") %>'>
就好了
Gomes 2011-11-12
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20111109/16/bca4bae5-2003-4e43-ada7-260e812dd333.html
谁能帮忙看下我这贴得问题吗!!
Gomes 2011-11-12
  • 打赏
  • 举报
回复
对头,没注意到给repeater 添加DataSource。

[Quote=引用 5 楼 sandy945 的回复:]

不是DataBind的问题,是你里层的repeater 没有指定 DataSource 导致

可以 google sandy945 repeater嵌套 Relations

DataBind ->父控件会遍历调用子控件
[/Quote]
阿非 2011-11-12
  • 打赏
  • 举报
回复
不是DataBind的问题,是你里层的repeater 没有指定 DataSource 导致

08年的时候写过例子,不过帖子忘了.

CSDN现在搜索不给力 只能google

google sandy945 repeater嵌套 Relations

DataBind ->父控件会遍历调用子控件
机器人 2011-11-12
  • 打赏
  • 举报
回复
Relations的确是做了关联,但Repeater没用DataBind()是不会Render Html的。
Gomes 2011-11-12
  • 打赏
  • 举报
回复
什么意思。不是已经用Relations关系了三个的关系吗。
不用ItemDataBound事件。
[Quote=引用 1 楼 fangxinggood 的回复:]

后面两 repeater 没用调用 DataBind 么?
[/Quote]

IHandler 2011-11-12
  • 打赏
  • 举报
回复
在上级Repeater的ItemDataBound事件中给下级Repeater绑定数据
机器人 2011-11-12
  • 打赏
  • 举报
回复
后面两 repeater 没用调用 DataBind 么?

62,046

社区成员

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

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

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

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