亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

實現(xiàn)無刷新閃爍二級聯(lián)動下拉菜單

系統(tǒng) 1619 0


先建立2個表



-- 父表
create ? table ?tb_parent(
-- 主鍵
ids? int ? constraint ?pk_tb_parent_ids? primary ? key ,
parentName?
nvarchar ( 1000 )
)
go

insert ? into ?tb_parent
????
select ? 1 , ' aaa '
????
union ? all
????
select ? 2 , ' bbb '
????
union ? all
????
select ? 3 , ' ccc '
go

?


-- 子表
create ? table ?tb_child(
parentId?
int ??,
childId?
int ?,
childName?
nvarchar ?( 1000 ),
-- parentId外鍵
constraint ?fk_tb_child_tb_parent_parentId?
????
FOREIGN ? KEY ?(parentId)?????
????????
REFERENCES ?tb_parent(ids)
)
go


insert ? into ?tb_child
????
select ? 1 , 101 , ' a_1 '
????
union ? all
????
select ? 1 , 102 , ' a_2 '
go
insert ? into ?tb_child
????
select ? 2 , 201 , ' b_1 '
????
union ? all
????
select ? 2 , 202 , ' b_2 '
go
insert ? into ?tb_child
????
select ? 3 , 301 , ' c_1 '
????
union ? all
????
select ? 3 , 302 , ' c_2 '
????
union ? all
????
select ? 3 , 303 , ' c_3 '
go

再創(chuàng)建3個過程


-- 得到父表數(shù)據(jù)
create ? proc ?proc_GetparentData
as
SELECT ? [ ids ] ,? [ parentName ] ?
????
FROM ? [ tb_parent ]
go


-- 得到子表數(shù)據(jù)
create ? proc ?proc_GetchildData
as
SELECT ? [ parentId ] ,? [ childId ] ,? [ childName ] ?
????
FROM ? [ tb_child ]
go

-- 由父id得到子表數(shù)據(jù)
create ? proc ?proc_GetchildDataBYparentId
@parentId ? int
as
SELECT ? [ parentId ] ,? [ childId ] ,? [ childName ] ?
????
FROM ? [ tb_child ]
????
where ?parentId = @parentId
go

WebForm5.aspx

?1 ? <% @?Page?language = " c# " ?Codebehind = " WebForm5.aspx.cs " ?AutoEventWireup = " false " ?Inherits = " webtest.WebForm5 " ? %>
?2 ? <! DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.0?Transitional//EN"? >
?3 ? < HTML >
?4 ? ???? < HEAD >
?5 ? ???????? < title > WebForm5 </ title >
?6 ? ???????? < meta? content ="Microsoft?Visual?Studio?.NET?7.1" ?name ="GENERATOR" >
?7 ? ???????? < meta? content ="C#" ?name ="CODE_LANGUAGE" >
?8 ? ???????? < meta? content ="JavaScript" ?name ="vs_defaultClientScript" >
?9 ? ???????? < meta? content ="http://schemas.microsoft.com/intellisense/ie5" ?name ="vs_targetSchema" >
10 ? ???? </ HEAD >
11 ? ???? < body? MS_POSITIONING ="GridLayout" >
12 ? ???????? < form? id ="Form1" ?method ="post" ?runat ="server" >
13 ? ????????????父: < asp:dropdownlist? id ="DropDownList_parent" ?runat ="server" ?onChange ="changevalue(document.Form1.DropDownList_parent.options[document.Form1.DropDownList_parent.selectedIndex].value)"
14 ? ????????????????Width ="272px" ></ asp:dropdownlist >
15 ? ???????????? < br >
16 ? ????????????子: < asp:dropdownlist? id ="DropDownList_child" ?runat ="server" ?Width ="272px" ></ asp:dropdownlist >
17 ? ???????????? < br >
18 ? ???????????? < asp:label? id ="msgLabel" ?runat ="server" ?Width ="416px" ></ asp:label >
19 ? ???????????? < br >
20 ? ???????????? < asp:Button? id ="Buttonok" ?runat ="server" ?Text ="click" ></ asp:Button ></ form >
21 ? ???? </ body >
22 ? </ HTML >

WebForm5.aspx.cs

??1 using ?System;
??2 using ?System.Collections;
??3 using ?System.ComponentModel;
??4 using ?System.Data;
??5 using ?System.Data.SqlClient;
??6 using ?System.Drawing;
??7 using ?System.Web;
??8 using ?System.Web.SessionState;
??9 using ?System.Web.UI;
?10 using ?System.Web.UI.WebControls;
?11 using ?System.Web.UI.HtmlControls;
?12 using ?System.Text;
?13
?14 using ?Microsoft.ApplicationBlocks.Data;
?15
?16 namespace ?webtest
?17 {
?18 ???? public ? class ?WebForm5?:?System.Web.UI.Page
?19 ???? {
?20 ???????? protected ?System.Web.UI.WebControls.DropDownList?DropDownList_parent;
?21 ???????? protected ?System.Web.UI.WebControls.DropDownList?DropDownList_child;
?22 ????????
?23 ???????? protected ?System.Web.UI.WebControls.Label?msgLabel;
?24 ???????? protected ?System.Web.UI.WebControls.Button?Buttonok;
?25
?26 ???????? readonly ? string ?conString = " uid=sa;pwd=123;database=TestDataBase " ;
?27 ????
?28 ???????? private ? void ?Page_Load( object ?sender,?System.EventArgs?e)
?29 ???????? {????
?30 ????????????????regJS();
?31 ????????????????Bind();
?32 ????????}

?33
?34 ???????? private ? void ?regJS()
?35 ???????? {
?36 ????????????SqlDataReader?rs = this .GetchildData();
?37 ????????????StringBuilder?sb = new ?StringBuilder( 1000 );
?38
?39 ????????????sb.Append( " <Script?Language=JavaScript> " );
?40 ????????????sb.Append(Environment.NewLine);
?41 ????????????
?42 ????????????sb.Append( " arr=new?Array(); " );
?43 ????????????sb.Append(Environment.NewLine);
?44 ????????????
?45 ???????????? int ?i = 0 ;
?46 ???????????? while (rs.Read())
?47 ???????????? {
?48 ????????????????sb.AppendFormat( " arr[{0}]=new?Array('{1}','{2}','{3}') " ,i,rs[ " parentId " ],rs[ " childId " ],rs[ " childName " ]);
?49 ????????????????sb.Append(Environment.NewLine);
?50 ????????????????i = i + 1 ;
?51 ????????????}

?52 ????????????
?53 ???????????? if ?(? ! rs.IsClosed?)
?54 ???????????? {
?55 ????????????????rs.Close();
?56 ????????????}

?57
?58 ????????????sb.Append(Environment.NewLine);
?59 ????????????sb.AppendFormat( " var?counts={0} " ,i);
?60 ????????????sb.Append(Environment.NewLine);
?61 ????????????sb.Append( " function?changevalue(parentId) " );
?62 ????????????sb.Append(Environment.NewLine);
?63 ????????????sb.Append( " { " );
?64 ????????????sb.Append(Environment.NewLine);
?65 ????????????sb.Append( " document.Form1.DropDownList_child.length?=?0; " );
?66 ????????????sb.Append(Environment.NewLine);
?67 ????????????sb.Append( " var?i; " );
?68 ????????????sb.Append(Environment.NewLine);
?69 ????????????sb.Append( " for(i=0;?i<counts;?i++) " );
?70 ????????????sb.Append(Environment.NewLine);
?71 ????????????sb.Append( " { " );
?72 ????????????sb.Append(Environment.NewLine);
?73 ????????????sb.Append( " if(arr[i][0]==parentId) " );
?74 ????????????sb.Append(Environment.NewLine);
?75 ????????????sb.Append( " { " );
?76 ????????????sb.Append(Environment.NewLine);
?77 ????????????sb.Append( " document.Form1.DropDownList_child.options[document.Form1.DropDownList_child.length]=new?Option(arr[i][2],arr[i][1]); " );
?78 ????????????sb.Append(Environment.NewLine);
?79 ????????????sb.Append( " } " );
?80 ????????????sb.Append(Environment.NewLine);
?81 ????????????sb.Append( " } " );
?82 ????????????sb.Append(Environment.NewLine);
?83 ????????????sb.Append( " } " );
?84 ????????????sb.Append(Environment.NewLine);
?85 ????????????sb.Append( " </script> " );????????????
?86 ????????????????????????
?87 ???????????? if (? ! Page.IsClientScriptBlockRegistered( " jsScript " ))????????????
?88 ???????????? {
?89 ???????????????? this .RegisterClientScriptBlock( " jsScript " ,sb.ToString());
?90 ????????????}

?91 ????????}

?92
?93 ???????? void ?Bind()
?94 ???????? {
?95 ???????????? // 獲得父表
?96 ???????????? this .DropDownList_parent.DataSource = SqlHelper.ExecuteReader(conString,CommandType.StoredProcedure, " proc_GetparentData " );
?97 ???????????? this .DropDownList_parent.DataTextField = " parentName " ;
?98 ???????????? this .DropDownList_parent.DataValueField = " ids " ;
?99 ???????????? this .DropDownList_parent.DataBind();
100
101 ???????????? // 根據(jù)父表id得子表
102 ???????????? this .DropDownList_child.DataSource = GetchildData(Convert.ToInt32( this .DropDownList_parent.SelectedValue));
103 ???????????? this .DropDownList_child.DataTextField = " childName " ;
104 ??????????

實現(xiàn)無刷新閃爍二級聯(lián)動下拉菜單


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 在线观看日本免费视频大片一区 | 久热精品免费视频 | 狠狠色狠狠色 | 日韩大乳视频中文字幕 | 精品老司机在线观看视频 | 99热欧美| 久久精品国产91久久麻豆自制 | 日韩精品一区二区三区中文精品 | 欧美视频在线不卡 | 在线视频综合视频免费观看 | 99热这里只有精品国产在热久久 | 日韩在线手机看片免费看 | 欧美人zoxxxx另类 | 一个色在线 | 亚洲欧洲视频 | 国产成人精品日本亚洲语言 | 国产在线精品一区二区高清不卡 | 大杳蕉伊人狼人久久一本线 | 久草精品视频在线观看 | 成人午夜视频在线 | 3d动漫精品成人一区二区三 | 亚洲欧美中文字幕高清在线一 | 国产成人午夜片在线观看 | 国产一区在线看 | 欧美成人看片黄a免费 | 久久综合综合久久狠狠狠97色 | 中国美女一级毛片 | 久久在草| 天天综合在线观看 | 亚洲 欧美 中文 日韩欧美 | 免费毛片a | 成人短视频在线在线观看 | 奇米影视小说 | 国产福利视频一区 | 四虎国产免费 | 99re热精品视频国产免费 | 精品久久久久久中文字幕2017 | 四虎在线永久精品高清 | 神马影院我不卡888 神马影院我不卡手机 | 日本精品久久久一区二区三区 | 午夜影院免费 |