分类导航运用CSS控制UpdatePane
<style type="text/css">
.my_left_category
{
width: 130px;
font-size: 12px;
font-family: arial,sans-serif;
letter-spacing: 2px;
border:#8BD0F6 2px solid;
}
.my_left_category h1
{
background-image: url(../image/1_1853261.gif);
height: 20px;
background-repeat: no-repeat;
font-size: 14px;
font-weight: bold;
padding-left: 15px;
padding-top: 8px;
margin: 0px;
}
.my_left_category h1 a
{
color: #7BC2E7;
}
.my_left_category h1 a:hover
{
color: #2268C8;
}
.my_left_category .my_left_cat_list
{
width: 128px;
border-color: #8BD0F6;
border-style: solid;
border-width: 0px 1px 1px 1px;
line-height: 13.5pt;
}
.my_left_category .h2_cat
{
width: 128px;
height: 26px;
background-color: #F3FBFF;
background-repeat: no-repeat;
line-height: 26px;
font-weight: normal;
color: #333333;
position: relative;
border-bottom:#8BD0F6 1px solid;
}
.my_left_category a
{
font: 12px;
text-decoration: none;
color: #333333;
}
.my_left_category a:hover
{
text-decoration: underline;
}
.my_left_category h3
{
margin: 0px;
padding: 0px;
height: 26px;
font-size: 12px;
font-weight: normal;
display: block;
padding-left: 8px;
}
.my_left_category h3 span
{
color: #999999;
width: 125px;
float: right;
}
.my_left_category h3 a
{
line-height: 26px;
color: #2268C8;
letter-spacing: 5px;
font-size: 12px
}
.my_left_category .h3_cat
{
display: none;
width: 404px;
position: absolute;
left: 113px;
margin-top: -27px;
cursor: auto;
}
.my_left_category .shadow
{
position: inherit;
background: url(../image/1_185541.gif) left top;
width: 404px;
}
.my_left_category .shadow_border
{
position: inherit;
width: 400px;
border: 3px solid #4BB0DE;
margin-top: 1px;
background-color:#F3FBFF;
margin-bottom: 3px;
}
.my_left_category .shadow_border ul
{
margin: 0;
padding: 0;
margin-left: 15px;
}
.my_left_category .shadow_border ul li
{
list-style: none;
padding-left: 10px;
background-image: url(../image/1_185704.gif);
background-repeat: no-repeat;
background-position: 0px 8px;
float: left;
height: 25px;
overflow: hidden;
letter-spacing: 0px;
margin-right:10px;
}
.shadow_sanji
{
padding-left:90px;
display: block;
}
.shadow_sanji li
{
margin: 0px 5px;
padding: 0px;
}
.my_left_category .active_cat
{
z-index: 99;
background-position: 0 -25px;
cursor: pointer;
background-color:#4BB0DE;
}
.my_left_category .active_cat h3 a
{
font-weight: bold;
font-size: 11px;
color:#FFFFFF;
text-decoration: none;
}
.my_left_category .active_cat div
{
display: block;
}
</style>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:DropDownList ID="ddlpszx" runat="server">
</asp:DropDownList><br />
<br />
<div class="my_left_category">
<h1>
<a href="../dd/yhdd.aspx">全部商品分类</a></h1>
<div class="my_left_cat_list">
<asp:Repeater ID="dalei" runat="server" OnItemDataBound="dalei_ItemDataBound">
<ItemTemplate>
<div class="h2_cat" οnmοuseοver="this.className='h2_cat active_cat'" οnmοuseοut="this.className='h2_cat'">
<h3>
<asp:Image ID="Image1" runat="server" ImageUrl="../image/1_185704.gif" />
<a href="../dd/yhdd.aspx?splbbh=<%# Eval("splbbh")%>">
<%# Eval("splbmc") %>
</a>
</h3>
<div class="h3_cat">
<div class="shadow">
<div class="shadow_border">
<ul>
<asp:Repeater ID="RepCategory" runat="server" OnItemDataBound="RepCategory_ItemDataBound">
<ItemTemplate>
<li><a href="../dd/yhdd.aspx?splbbh=<%# Eval("splbbh")%>" style="color: #2268C8;
font-weight: bold; font-size: 12px;">
<%# Eval("splbmc") %>
</a></li>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<div class="shadow_sanji">
</HeaderTemplate>
<ItemTemplate>
<li><a href="../dd/yhdd.aspx?splbbh=<%# Eval("splbbh")%>">
<%# Eval("splbmc") %>
</a></li>
</ItemTemplate>
<FooterTemplate>
<br />
<br />
</div>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
private SqlConnection Conn = null;
private static string connString = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = splbda(1);
dalei.DataSource = dt;
dalei.DataBind();
}
public DataTable splbda(int jc)
{
this.Conn = new SqlConnection(connString);
string mysql = "Select splbbh ,splbmc,fbbh,jc from splbda where jc=" + jc + "";
DataTable dt = new DataTable();
SqlDataAdapter sqlda = new SqlDataAdapter(mysql, this.Conn);
try
{
if (this.Conn.State == ConnectionState.Closed)
{
this.Conn.Open();
}
sqlda.Fill(dt);
}
catch (Exception exception)
{
HttpContext.Current.Response.Write(exception.Message);
HttpContext.Current.Response.End();
}
finally
{
if ((this.Conn != null) && (this.Conn.State == ConnectionState.Open))
{
this.Conn.Close();
}
sqlda.Dispose();
}
return dt;
}
public DataTable xiaji(string fbbh)
{
this.Conn = new SqlConnection(connString);
string mysql = "Select splbbh ,splbmc,fbbh,jc from splbda where fbbh='" + fbbh + "'";
DataTable dt = new DataTable();
SqlDataAdapter sqlda = new SqlDataAdapter(mysql, this.Conn);
try
{
if (this.Conn.State == ConnectionState.Closed)
{
this.Conn.Open();
}
sqlda.Fill(dt);
}
catch (Exception exception)
{
HttpContext.Current.Response.Write(exception.Message);
HttpContext.Current.Response.End();
}
finally
{
if ((this.Conn != null) && (this.Conn.State == ConnectionState.Open))
{
this.Conn.Close();
}
sqlda.Dispose();
}
return dt;
}
protected void dalei_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rp = (Repeater)e.Item.FindControl("RepCategory"); //找里面的RP
DataRowView drv = (DataRowView)e.Item.DataItem;
//int caid = Convert.ToInt32(drv["ClassifyID"]); //获取ID
string scaid = drv["splbbh"].ToString();
rp.DataSource = this.xiaji(scaid); //根据外边的大类获取数据源
rp.DataBind();
}
}
protected void RepCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rp = (Repeater)e.Item.FindControl("Repeater1"); //找里面的RP
DataRowView drv = (DataRowView)e.Item.DataItem;
//int caid = Convert.ToInt32(drv["ClassifyID"]); //获取ID
string scaid = drv["splbbh"].ToString();
rp.DataSource = this.xiaji(scaid); //根据外边的大类获取数据源
rp.DataBind();
if (this.xiaji(scaid).Rows.Count == 0)
{
rp.Visible = false;
}
}
}
}