百度空间 | 百度首页 
 
查看文章
 
无刷新三级连动用户控件2
2008-10-16 11:22

1<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ThreeLevelDropdownList.ascx.cs" Inherits="controls_ThreeLevelDropdownList" %>
2<asp:DropDownList ID="ddl1" runat="server">
3</asp:DropDownList>&nbsp;&nbsp;
4<asp:DropDownList ID="ddl2" runat="server">
5<asp:ListItem Text="请选择" Value="0"></asp:ListItem>
6</asp:DropDownList>&nbsp;&nbsp;
7<asp:DropDownList ID="ddl3" runat="server">
8<asp:ListItem Text="请选择" Value="0"></asp:ListItem>
9</asp:DropDownList>&nbsp;&nbsp;<br />
10
11<asp:HiddenField ID="hdf1" runat="server" /><asp:HiddenField ID="hdf2" runat="server" /><asp:HiddenField ID="hdf3" runat="server" />
12<script type="text/javascript" language="javascript">
13<!--
14       //常用JS函数
15       function getBid(s){
16          return document.getElementById(s);
17        }
18        function getBmc(s){
19          return document.getElementByName(s);
20        }
21
22       //显示分类列表
23       function showNext(sid,obj,type)
24        {
25          if(sid==null || sid=="" || sid.length<1)return;
26          var slt =getBid(obj);
27          var v = controls_ThreeLevelDropdownList.GetLevelList(sid,type).value; // 类的名称
28
29
30          if (v != null){
31          if(v != null && typeof(v) == "object" && v.Tables != null)
32                    {
33                        slt.length = 0;
34                        slt.options.add(new Option("请选择",0));
35                        //加了个“请选择”主要为了触发onchange事件
36                        if(obj=="ddl2"){
37                        getBid("ddl3").options.length=0;
38                        getBid("ddl3").options.add(new Option("请选择",0));
39                        }
40                        for(var i=0; i<v.Tables[0].Rows.length; i++)
41                 {
42                     var txt = v.Tables[0].Rows[i].txt; //这个地方需要注意区分大小写
43                 var val = v.Tables[0].Rows[i].val; //跟dataset表的列名称要一致
44                 slt.options.add(new Option(txt,val));
45                 }
46                    }
47           }
48           return;
49        }
50
51        //保留Select中选择的值
52        function selectValue(sid,obHdf)
53        {
54          getBid(obHdf).value=sid;
55          //alert(getBid(obHdf).value);   
56        }
57        -->
58</script>
59
1<%@ Register TagPrefix="uc1" TagName="ThreeLevelDropdownList" Src="http://www.cnblogs.com/controls/ThreeLevelDropdownList.ascx" %>
2<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JobList.aspx.cs" Inherits="Manager_Job_JobList"  %>
3
4<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6<html xmlns="http://www.w3.org/1999/xhtml" >
7<head runat="server">
8    <title>无标题页</title>
9</head>
10<body>
11    <form id="form1" runat="server">
12    <div>
13      所在地区<uc1:ThreeLevelDropdownList id="threeLevelDDL1" runat="server"  ></uc1:ThreeLevelDropdownList><br />
14      工作类型<uc1:ThreeLevelDropdownList id="threeLevelDDL2" runat="server"  ></uc1:ThreeLevelDropdownList><br /><br />
15        <asp:Button ID="Button1" runat="server" Text="Button" />
16    </div>
17    </form>
18</body>
19</html>
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class Manager_Job_JobList : System.Web.UI.Page
13{
14
15    protected void Page_Load(object sender, EventArgs e)
16    {
17
18        if (!IsPostBack)
19        {
20            /**//*3级连动初始化*/
21            //1 供求信息 2人才招聘 3地区
22            threeLevelDDL1.Type = "3";
23            threeLevelDDL2.Type = "2";
24            /**//*3级连动初始化*/
25
26
27
28            /**//*=========================获取选择值  服务端方法 =========================================*/
29               // string type1=threeLevelDDL1.selValue1;
30               // string type2 = threeLevelDDL1.selValue2;
31               // string type3 = threeLevelDDL1.selValue3;      
32             /**//*========================================================================================*/
33
34
35            /**//*========================获取选择值   客户端方法======================================*/
36
37             //用户控件id+"_"+hdf1 =hdf1的clientId    保存的是第一级下拉的值,其他类推
38             //
39            /**//*====================================================================================== */
40        }
41    }
42}

类别:asp.net 知识 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu