.aspx代码
======================
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type="text/css"> <!-- .style2 {color: #000000}
-->
</style>
<script language="javascript" type="text/javascript">
function showMenu(id,count)
{
td_id = eval("td" + id);
if (td_id.style.display == "none")
{
for(var num=0;num<Number(count);num++)
{
var tdid = String(num);
eval("td" + tdid + ".style.display=\"none\";");
}
eval("td" + id+ ".style.display=\"\";");
}
}
</script>
</head>
<body>
<form >
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
.cs文件
=========================================
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 TwoQQ : System.Web.UI.Page
{
private string connectionstring = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
private void BindData()
{
SqlConnection com = new SqlConnection(connectionstring);
string sqlStr = " select * from tb_parent ";
SqlDataAdapter dal = new SqlDataAdapter(sqlStr,com);
DataSet ds = new DataSet();
dal.Fill(ds, "db_Menu");
DataView dv = ds.Tables["db_Menu"].DefaultView;
for (int i = 0; i < dv.Count;i++ )
{
//一级目录
HtmlTableRow myrow = new HtmlTableRow();
tabMenu.Rows.Add(myrow);
HtmlTableCell mycell = new HtmlTableCell();
myrow.Cells.Add(mycell);
mycell.Height = "22px";
mycell.Width = "160px";
mycell.Width = "100%";
mycell.Align = "center";
mycell.Attributes.Add("OnClick", "showMenu('"+i+"','"+dv.Count+"')");
mycell.Attributes.Add("style", "cursor:hand");
mycell.InnerHtml = dv[i]["parentName"].ToString();
//二级目录
int ParentID = Convert.ToInt32(dv[i]["ids"].ToString());
string strSql2 = "select * from tb_child where parentId="+ParentID;
SqlDataAdapter dal2 = new SqlDataAdapter(strSql2,com);
DataSet ds2 = new DataSet();
dal2.Fill(ds2, "db_Menu");
DataView dv2 = ds2.Tables["db_Menu"].DefaultView;
HtmlTableRow myrow2 = new HtmlTableRow();
tabMenu.Rows.Add(myrow2);
HtmlTableCell mycell2 = new HtmlTableCell();
myrow2.Cells.Add(mycell2);
//// mycell2.BgColor = "#336699";
mycell2.Width = "100%";
mycell2.Align = "center";
mycell2.ID = "td" + i.ToString();
mycell2.Height = "100%";
if (i != 0)
{
mycell2.Style["display"]="none";
}
mycell2.VAlign = "top";
HtmlTable mytable = new HtmlTable();
mycell2.Controls.Add(mytable);
for (int j = 0; j < dv2.Count;j++ )
{
HtmlTableRow mytablerow = new HtmlTableRow();
mytable.Rows.Add(mytablerow);
HtmlTableCell mytablecell = new HtmlTableCell();
mytablerow.Cells.Add(mytablecell);
mytablecell.Width = "100%";
mytablecell.Height = "22px";
mytablecell.Align = "center";
mytablecell.InnerHtml = "<a href='aa.aspx?;
}
}
}
}