.NET中实现无刷新客户端联动下拉菜单

None.gif.NET中实现无刷新客户端联动下拉菜单 (无刷新) (通过下拉菜单动态显示不同图片也可也该方法实现)
None.gif
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CustomManager.company.WebForm1" %>
None.gif
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
<HTML>
None.gif 
<HEAD>
None.gif  
<title>WebForm1</title>
None.gif  
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
None.gif  
<meta content="C#" name="CODE_LANGUAGE">
None.gif  
<meta content="JavaScript" name="vs_defaultClientScript">
None.gif  
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
None.gif  
<LINK href="../css/style.css" type="text/css" rel="stylesheet">
None.gif 
</HEAD>
None.gif 
<body MS_POSITIONING="GridLayout">
None.gif  
<form id="Form1" method="post" runat="server">
None.gif   
<asp:dropdownlist id="DropDownList1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 168px"
None.gif    runat
="server"></asp:dropdownlist>
None.gif
None.gif
<!--以下的label中隐藏存放一级栏目和二级栏目对应的内容-->
None.gif
<asp:label id="Label1" style="display:none;" runat="server">Label</asp:label>
None.gif
None.gif
None.gif   
<asp:DropDownList id="DropDownList2" style="Z-INDEX: 104; LEFT: 40px; POSITION: absolute; TOP: 264px"
None.gif    runat
="server"></asp:DropDownList></form>
None.gif
<script LANGUAGE="javascript">
None.gif
//将隐藏的字符串取出来,然后分割到一个数组中去
None.gif
var str = document.getElementById("Label1").innerText;
None.gifarr
=str.split(",");
None.gifa
=arr.length
None.gifar
=new Array()
ExpandedBlockStart.gifContractedBlock.gif
for (i=0;i<a;i++)dot.gif{
InBlock.gif  ar[i]
=arr[i].split("-");
ExpandedBlockEnd.gif}

None.gifonecount
=ar.length;
None.gif
None.gif
None.gif
//此处实现联动
ExpandedBlockStart.gifContractedBlock.gif
function  ld() dot.gif{
InBlock.gif  document.Form1.DropDownList2.length
=0
InBlock.gif  lid
=Form1.DropDownList1.value;       
ExpandedSubBlockStart.gifContractedSubBlock.gif  
for  (i=0;i<onecount;i++)  dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if  (ar[i][0]  ==  lid) dot.gif{
InBlock.gif   document.Form1.DropDownList2.options.add(
new Option(ar[i][2],  ar[i][1]));    
ExpandedSubBlockEnd.gif    }
    
ExpandedSubBlockEnd.gif  }
   
ExpandedBlockEnd.gif}
  
ExpandedBlockStart.gifContractedBlock.gif
/**//*换图片的方法
InBlock.giffunction changeimg()
InBlock.gif{
InBlock.gif document.Form1.faceimage.src="images/face/"+document.Form1.userface.value;
InBlock.gif}
InBlock.gif
ExpandedBlockEnd.gif
*/

None.giffunction showMsg()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif alert(document.Form1.DropDownList1.value);
InBlock.gif alert(document.Form1.DropDownList2.value);
ExpandedBlockEnd.gif}

None.gif
None.gif  
</script>
None.gif 
</body>
None.gif
</HTML>
None.gif
None.gif
None.gif
None.gif以下是WebForm1.aspx.cs
None.gif
None.gif
using System;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.Data;
None.gif
using System.Drawing;
None.gif
using System.Web;
None.gif
using System.Web.SessionState;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.HtmlControls;
None.gif
None.gif
namespace CustomManager.company
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif 
/**//// <summary>
InBlock.gif 
/// WebForm1 的摘要说明。
ExpandedSubBlockEnd.gif 
/// </summary>

InBlock.gif public class WebForm1 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
protected System.Web.UI.WebControls.DropDownList DropDownList1;
InBlock.gif  
protected System.Web.UI.WebControls.Label Label1;
InBlock.gif  
protected System.Web.UI.WebControls.DropDownList DropDownList2;
InBlock.gif  
static protected DataTable tb1;
InBlock.gif 
InBlock.gif  
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
// 在此处放置用户代码以初始化页面
InBlock.gif

InBlock.gif   
if(!Page.IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
ExpandedSubBlockEnd.gif   }

InBlock.gif
InBlock.gif
//给DropDownList1设置onchange事件
InBlock.gif
   DropDownList1.Attributes.Add("onchange","ld();");
InBlock.gif   
string strConn,strSql;
InBlock.gif   System.Data.SqlClient.SqlDataAdapter da;
InBlock.gif   
InBlock.gif
InBlock.gif
//从数据库中取出一级栏目,绑定到     DropDownList1
InBlock.gif
strConn = "server=localhost;database=custom;uid=custom;pwd=a;";
InBlock.gif   strSql 
= "select * from custom.bigcalling;";
InBlock.gif   da 
= new System.Data.SqlClient.SqlDataAdapter(strSql,strConn);
InBlock.gif   DataTable tb3 
= new DataTable();
InBlock.gif   da.Fill(tb3);
InBlock.gif
InBlock.gif   DropDownList1.DataSource 
= tb3;
InBlock.gif   DropDownList1.DataTextField 
= "BIGCALLNAME";
InBlock.gif   DropDownList1.DataValueField
= "BIGCALLID";
InBlock.gif   DropDownList1.DataBind();
InBlock.gif
InBlock.gif
//取出二级栏目数据,存放到一个DataTable()中
InBlock.gif
   strSql = "select * from custom.smallcalling;";
InBlock.gif   da 
= new System.Data.SqlClient.SqlDataAdapter(strSql,strConn);
InBlock.gif   tb1 
= new DataTable();
InBlock.gif   da.Fill(tb1);
InBlock.gif
InBlock.gif
InBlock.gif
//以下就是将一级和二级菜单的内容,分别以"-"和","隔开
InBlock.gif
//然后存放到 Label1中,这样客户端就可以通过脚本取得所需要的数据了
InBlock.gif
   Label1.Text = "";
InBlock.gif
InBlock.gif   
foreach(DataRow row in tb1.Rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Label1.Text 
= Label1.Text  + row["BIGCALLID"+ "-" +row["SMALLCALLID"+ "-"+row["SMALLCALLNAME"+ ",";
InBlock.gif
ExpandedSubBlockEnd.gif   }

InBlock.gif
ExpandedSubBlockEnd.gif  }

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

InBlock.gif  
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif  
/// 此方法的内容。
ExpandedSubBlockEnd.gif  
/// </summary>

InBlock.gif  private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{    
InBlock.gif   
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif  
#endregion

InBlock.gif
InBlock.gif  
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif
None.gif

转载于:https://www.cnblogs.com/bbisky/archive/2006/03/01/340407.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值