我想用两个Repeater控件来实现树型结构。第一个Repeater控件来显示主分类,当点击某主分类时,在其主分类正下面动态添加另一个Repeater控件。
html
---------------------------------
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<div style="border:1px solid lightblue;"><img id='parent<%# DataBinder.Eval(Container.DataItem,"au_id")%>' src="http://localhost/webctrl_client/1_0/treeimages/Rplus.gif"><%# DataBinder.Eval(Container.DataItem,"au_id")%></div>
<div id='parent<%# DataBinder.Eval(Container.DataItem,"au_id")%>Contanor' style="display:block;padding-left:20px">
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"au_lname")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"au_fname")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"phone")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"address")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"city")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"state")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"zip")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"contract")%></div>
</div>
</ItemTemplate>
</asp:Repeater>
-------------------------------------------------------------
javascript
------------------------------
<script language="javascript">
var imgs=document.getElementsByTagName("IMG");
for(i=0;i<imgs.length;i )
{
imgs[i].onclick=function aa()
{
var obj=window.event.srcElement;
var con=document.getElementById(obj.id "Contanor");
if(con.style.display=="none")
{con.style.display="block"}
else
{con.style.display="none"}
}
}
</script>
---------------------------------------------------------------------
cs
-----------------------------------------
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
string sqlSTR="select * from authors";
System.Data.SqlClient.SqlDataAdapter dat = new SqlDataAdapter(sqlSTR,con);
DataSet ds = new DataSet();
dat.Fill(ds,"authors");
this.Repeater1.DataSource=ds.Tables["authors"].DefaultView;
this.Repeater1.DataBind();
以pubs数据库authors表做例子
html
---------------------------------
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<div style="border:1px solid lightblue;"><img id='parent<%# DataBinder.Eval(Container.DataItem,"au_id")%>' src="http://localhost/webctrl_client/1_0/treeimages/Rplus.gif"><%# DataBinder.Eval(Container.DataItem,"au_id")%></div>
<div id='parent<%# DataBinder.Eval(Container.DataItem,"au_id")%>Contanor' style="display:block;padding-left:20px">
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"au_lname")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"au_fname")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"phone")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"address")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"city")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"state")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"zip")%></div>
<div style="border:1px solid lightblue;"><%# DataBinder.Eval(Container.DataItem,"contract")%></div>
</div>
</ItemTemplate>
</asp:Repeater>
-------------------------------------------------------------
javascript
------------------------------
<script language="javascript">
var imgs=document.getElementsByTagName("IMG");
for(i=0;i<imgs.length;i )
{
imgs[i].onclick=function aa()
{
var obj=window.event.srcElement;
var con=document.getElementById(obj.id "Contanor");
if(con.style.display=="none")
{con.style.display="block"}
else
{con.style.display="none"}
}
}
</script>
---------------------------------------------------------------------
cs
-----------------------------------------
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
string sqlSTR="select * from authors";
System.Data.SqlClient.SqlDataAdapter dat = new SqlDataAdapter(sqlSTR,con);
DataSet ds = new DataSet();
dat.Fill(ds,"authors");
this.Repeater1.DataSource=ds.Tables["authors"].DefaultView;
this.Repeater1.DataBind();
以pubs数据库authors表做例子