用ajax(vb.net) 实现dropdownlist二级无刷新联动~!

说说vb.net ajaxpro 实现dropdownlist二级无刷新联动~!
ContractedBlock.gif ExpandedBlockStart.gif 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是服务器控件绑定,很方便~!
ContractedBlock.gif ExpandedBlockStart.gif 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)将返回一个[object object]类型
alert(res.rows)将返回一个object类型
alert(res.rows[0].value)将返回一个[object object]类型
如果返回null类型,接收不到datatable数据,则可能是你的ajaxpro.2.dll并不支持datatable输出,建议你下载文章末尾ajaxpro.2.dll附件~!
vb.net写法:
ContractedBlock.gif ExpandedBlockStart.gif Code
Sub Page_Load() Sub Page_Load(ByVal sender As ObjectByVal 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对象将查询数据存入datatable中~!

ajaxpro.2.dll

转载于:https://www.cnblogs.com/opper/archive/2009/01/09/1372846.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值