.NET中实现无客户端联动菜单 (无刷新)

1@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CustomManager.company.WebForm1" 
 1<html>
 2<head>
 3<title>WebForm1</title>
 4<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"/>
 5<meta content="C#" name="CODE_LANGUAGE"/>
 6<meta content="JavaScript" name="vs_defaultClientScript"/>
 7<meta content=" http://schemas.microsoft.com/intellisense/ie5 " name="vs_targetSchema"/>
 8<link href="../css/style.css" rel="stylesheet" type="text/css"/>
 9</head>
10<body ms_positioning="GridLayout">
11<form id="Form1" method="post" runat="server">
12<asp:dropdownlist id="DropDownList1" runat="server" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 168px"></asp:dropdownlist><asp:label id="Label1" runat="server" style="Z-INDEX: 102; LEFT: 328px; POSITION: absolute; TOP: 104px">Label</asp:label>
13<asp:dropdownlist id="DropDownList2" runat="server" style="Z-INDEX: 104; LEFT: 40px; POSITION: absolute; TOP: 264px"></asp:dropdownlist></form>
14<script language="javascript">   
15var str = document.getElementById("Label1").innerText;   
16arr=str.split(",");   
17a=arr.length   
18ar=new Array()   
19for (i=0;i<a;i++){   
20ar[i]=arr[i].split("-");   
21}   
22onecount=ar.length; 
23
24  
25function ld() {   
26document.Form1.DropDownList2.length=0   
27lid=Form1.DropDownList1.value;   
28for (i=0;i<onecount;i++) {   
29if (ar[i][0] == lid) {   
30document.Form1.DropDownList2.options.add(new Option(ar[i][2], ar[i][1]));   
31}   
32}   
33} 
34
35function showMsg()   
36{   
37alert(document.Form1.DropDownList1.value);   
38alert(document.Form1.DropDownList2.value);   
39} 
40
41</script>
42</body>
43</html>

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CustomManager.company
{
///

1<summary>   
2/// WebForm1 的摘要说明。   
3/// </summary>

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
static protected DataTable tb1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面

if(!Page.IsPostBack)
{

}
DropDownList1.Attributes.Add("onchange","ld();");
string strConn,strSql;
System.Data.SqlClient.SqlDataAdapter da;

strConn = "server=localhost;database=custom;uid=custom;pwd=a;";
strSql = "select * from custom.bigcalling;";
da = new System.Data.SqlClient.SqlDataAdapter(strSql,strConn);
DataTable tb3 = new DataTable();
da.Fill(tb3);

DropDownList1.DataSource = tb3;
DropDownList1.DataTextField = "BIGCALLNAME";
DropDownList1.DataValueField= "BIGCALLID";
DropDownList1.DataBind();

strSql = "select * from custom.smallcalling;";
da = new System.Data.SqlClient.SqlDataAdapter(strSql,strConn);
tb1 = new DataTable();
da.Fill(tb1);

Label1.Text = "";

foreach(DataRow row in tb1.Rows)
{
Label1.Text = Label1.Text + row["BIGCALLID"] + "-" +row["SMALLCALLID"] + "-"+row["SMALLCALLNAME"] + ",";

}

}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///

1<summary>   
2/// 设计器支持所需的方法 - 不要使用代码编辑器修改   
3/// 此方法的内容。   
4/// </summary>

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

}
}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus