如何实现像商城网站上的商业行业分类的效果

来源:互联网 发布:周公解梦是真的吗 知乎 编辑:程序博客网 时间:2024/05/01 00:54

 前台HTML

<table width="100%" cellpadding="0" cellspacing="0" class="tableBorder">
    <TBODY>
     <tr vAlign="top">
      <td class="details_txt">
       <asp:datalist id="DataList1" runat="server" Width="100%" RepeatColumns="3"  CellSpacing="9"  CellPadding="30"
        DataKeyField="typeid" >
        <ItemStyle VerticalAlign="Top"></ItemStyle>
        <ItemTemplate><img src="images/303.gif">
         <a href ='WebForm1.aspx?typeid=<%#DataBinder.Eval(Container.DataItem,"typeID")%>'><b>
           <%#DataBinder.Eval(Container.DataItem,"name")%>
          </b></a>
         <br>
         <asp:Repeater id='Repeater1' enableviewstate='false' runat='server'>
          <HeaderTemplate>
           <table width="100%">
            <tr>
          </HeaderTemplate>
          <ItemTemplate>
           <a href ='WebForm1.aspx?typeid=<%#DataBinder.Eval(Container.DataItem,"typeID")%>'>
            <%#DataBinder.Eval(Container.DataItem,"name")%>
           </a><font color="#000000">|</font>
          </ItemTemplate>
          <FooterTemplate>
      </td>
     </tr>
   </table>
   </FooterTemplate> </asp:Repeater> </ItemTemplate>
   </asp:datalist></TD></TR></TBODY></TABLE>

 

后台cs代码

 private void Page_Load(object sender, System.EventArgs e)
  {
   if(!IsPostBack)
   {    
    this.BindUp();
   }
  }
  /// <summary>
  /// 绑定
  /// </summary>
  private  void BindUp()
  {
    try
   {
     DataTable dt1=Connect.BindTable("SELECT * FROM TypeI   where  PARENTID='0'");   
     DataList1.DataSource=dt1;
     DataList1.DataBind();   
     conn.Close();     
   }
   catch(Exception exc)
   {
    conn.Close(); 
    string s = exc.ToString();
   }
  }
  private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
  {
   Repeater myRepeater = (Repeater)e.Item.FindControl("Repeater1");           
   if(myRepeater != null)
   {    
    try
    {
     DataTable dt=Connect.BindTable("select * from  Type    where  len(typeid)=10  AND  left(parentId,4)='" + DataList1.DataKeys[e.Item.ItemIndex].ToString()+"'");   
     myRepeater.DataSource=dt;
     myRepeater.DataBind();    
     conn.Close();
    }
    catch(Exception exc)
    {
     conn.Close(); 
     string s = exc.ToString();
    }
   }
  }

原创粉丝点击