用ajax(vb.net) 实现dropdownlist二级无刷新联动~!
生活随笔
收集整理的這篇文章主要介紹了
用ajax(vb.net) 实现dropdownlist二级无刷新联动~!
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
說說vb.net ajaxpro 實(shí)現(xiàn)dropdownlist二級(jí)無刷新聯(lián)動(dòng)~! Code
<div?class="div_RSL">?
<asp:DropDownList?ID="DropDownList1"?runat="server"?DataSourceID="proID"?DataTextField="proName"AutoPostBack="false"?DataValueField="proID">?
</asp:DropDownList>?
<asp:SqlDataSource?ID="proID"?runat="server"?ConnectionString="<%$?ConnectionStrings:opperajaxConnectionString?%>"SelectCommand="SELECT?[proID],?[proName]?FROM?[TB_province]?ORDER?BY?[proID]"></asp:SqlDataSource>?
<asp:DropDownList?ID="DropDownList2"?runat="server">?
</asp:DropDownList>?
</div> 這里dropdownlist1是服務(wù)器控件綁定,很方便~! Code
function?ShowCity(id)?
{?
?????var?res=?Other_Register2.GetCity(id).value;?
?????var?drop?=?document.getElementById("<%=DropDownList2.UniqueID?%>");?
?????drop.length=0;?
?????for(var?i=0;i<res.Rows.length;i++)????
????????????{?????????
?????????????drop.options.add(new?Option(res.Rows[i].TB_cityName,res.Rows[i].TB_cityID));?
????????????}????
} ? alert(res)將返回一個(gè)[object object]類型 alert(res.rows)將返回一個(gè)object類型 alert(res.rows[0].value)將返回一個(gè)[object object]類型 如果返回null類型,接收不到datatable數(shù)據(jù),則可能是你的ajaxpro.2.dll并不支持datatable輸出,建議你下載文章末尾ajaxpro.2.dll附件~! vb.net寫法: Code
Sub?Page_Load()?Sub?Page_Load(ByVal?sender?As?Object,?ByVal?e?As?System.EventArgs)?Handles?Me.Load?
????If?Not?Page.IsPostBack?Then?
????????DropDownList1.Attributes("onchange")?=?"ShowCity(this.options[selectedIndex].value)"?
????End?If?????????
AjaxPro.Utility.RegisterTypeForAjax(GetType(Other_Register2))?
End?Sub?
Function?GetCity()?Function?GetCity(ByVal?sproid)?As?DataTable?
Dim?sqlconnection?As?New?SqlConnection(ShareFunction.GetDBConnectionString())?
sqlconnection.Open()?
Dim?sql?As?String?=?"select?TB_cityID,TB_cityName?from?TB_city?where?proID="?&?ShareFunction.SafeRequest(sproid,?1)?&?""?
Dim?dataada?As?New?SqlDataAdapter(sql,?sqlconnection)?
Dim?dt?As?New?DataTable?
dataada.Fill(dt)?
Return?dt?
End?Function
<div?class="div_RSL">?
<asp:DropDownList?ID="DropDownList1"?runat="server"?DataSourceID="proID"?DataTextField="proName"AutoPostBack="false"?DataValueField="proID">?
</asp:DropDownList>?
<asp:SqlDataSource?ID="proID"?runat="server"?ConnectionString="<%$?ConnectionStrings:opperajaxConnectionString?%>"SelectCommand="SELECT?[proID],?[proName]?FROM?[TB_province]?ORDER?BY?[proID]"></asp:SqlDataSource>?
<asp:DropDownList?ID="DropDownList2"?runat="server">?
</asp:DropDownList>?
</div> 這里dropdownlist1是服務(wù)器控件綁定,很方便~! Code
function?ShowCity(id)?
{?
?????var?res=?Other_Register2.GetCity(id).value;?
?????var?drop?=?document.getElementById("<%=DropDownList2.UniqueID?%>");?
?????drop.length=0;?
?????for(var?i=0;i<res.Rows.length;i++)????
????????????{?????????
?????????????drop.options.add(new?Option(res.Rows[i].TB_cityName,res.Rows[i].TB_cityID));?
????????????}????
} ? alert(res)將返回一個(gè)[object object]類型 alert(res.rows)將返回一個(gè)object類型 alert(res.rows[0].value)將返回一個(gè)[object object]類型 如果返回null類型,接收不到datatable數(shù)據(jù),則可能是你的ajaxpro.2.dll并不支持datatable輸出,建議你下載文章末尾ajaxpro.2.dll附件~! vb.net寫法: Code
Sub?Page_Load()?Sub?Page_Load(ByVal?sender?As?Object,?ByVal?e?As?System.EventArgs)?Handles?Me.Load?
????If?Not?Page.IsPostBack?Then?
????????DropDownList1.Attributes("onchange")?=?"ShowCity(this.options[selectedIndex].value)"?
????End?If?????????
AjaxPro.Utility.RegisterTypeForAjax(GetType(Other_Register2))?
End?Sub?
Function?GetCity()?Function?GetCity(ByVal?sproid)?As?DataTable?
Dim?sqlconnection?As?New?SqlConnection(ShareFunction.GetDBConnectionString())?
sqlconnection.Open()?
Dim?sql?As?String?=?"select?TB_cityID,TB_cityName?from?TB_city?where?proID="?&?ShareFunction.SafeRequest(sproid,?1)?&?""?
Dim?dataada?As?New?SqlDataAdapter(sql,?sqlconnection)?
Dim?dt?As?New?DataTable?
dataada.Fill(dt)?
Return?dt?
End?Function
這里使用dataadapter對(duì)象將查詢數(shù)據(jù)存入datatable中~!
ajaxpro.2.dll
轉(zhuǎn)載于:https://www.cnblogs.com/opper/archive/2009/01/09/1372846.html
總結(jié)
以上是生活随笔為你收集整理的用ajax(vb.net) 实现dropdownlist二级无刷新联动~!的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery系列(十四):jQuery中
- 下一篇: 易语言c编译,易语言命令行编译工具免费版