94969部队:无刷新联动二级菜单

来源:百度文库 编辑:神马品牌网 时间:2024/05/01 14:35:28
页面代码:
<HTML>
<HEAD>
<title>test</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 88px; POSITION: absolute; TOP: 168px"
runat="server" Width="192px" DataTextField="Menu" DataValueField="TID"></asp:DropDownList>
<asp:label id="Label1" style="DISPLAY:none" runat="server">Label</asp:label>
<asp:DropDownList id="DropDownList2" style="Z-INDEX: 102; LEFT: 368px; POSITION: absolute; TOP: 168px"
runat="server" Width="176px" DataTextField="LMenu" DataValueField="LID"></asp:DropDownList>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 208px; POSITION: absolute; TOP: 264px" runat="server"
Text="Button"></asp:Button>
</FONT>
</form>
<script LANGUAGE="javascript">
//将隐藏的字符串取出来,然后分割到一个数组中去
var str = document.getElementById("Label1").innerText;
arr=str.split(",");
a=arr.length
ar=new Array()
for (i=0;i<a;i++){
ar[i]=arr[i].split("-");
}
onecount=ar.length;

//此处实现联动
function ld() {
document.Form1.DropDownList2.length=0
lid=Form1.DropDownList1.value;
for (i=0;i<onecount;i++) {
if (ar[i][0] == lid) {
document.Form1.DropDownList2.options.add(new Option(ar[i][2], ar[i][1]));
}
}
}

function showMsg()
{
alert(document.Form1.DropDownList1.value);
alert(document.Form1.DropDownList2.value);
}

</script>
</body>
</HTML>
cs代码:
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
}
//给DropDownList1设置onchange事件
DropDownList1.Attributes.Add("onchange","ld();");

//1
dc.Connect(strconn);
string mysql="select TID,Menu from TopMenu";
DataSet ds=dc.ReturnDataSet(mysql,"TopMenu");
DropDownList1.DataSource=ds.Tables["TopMenu"];
DropDownList1.DataBind();
dc.Disconnect();

//2
dc.Connect(strconn);
SqlCommand cm=dc.ReturnCommand();
cm.CommandType=CommandType.StoredProcedure;
cm.CommandText="A_GetRank1";
cm.Parameters.Add("@Flag",SqlDbType.Int);
cm.Parameters["@Flag"].Value=6;
SqlDataAdapter da = new SqlDataAdapter(cm);
DataSet ds1 = new DataSet();
da.Fill(ds1,"LeftMenu");

dc.Disconnect();

Label1.Text="";
foreach(DataRow row in ds1.Tables["LeftMenu"].Rows)
{
Label1.Text = Label1.Text + row["TID"] + "-" +row["LID"] + "-"+row["LMenu"] + ",";

}

功能已经实现了,但我不知道怎么来获取页面上
2个dropdownlist的值,请问我应该怎么来获取?
谢谢

.cs文件里用
Request.Form[]获取试试