VB   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了vb.net 实现dropdownlist二级无刷新联动~!大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
说说vb.net ajaxpro 实现dropdownlist二级无刷新联动~!
Html写法:
< 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是服务器控件绑定,很方便~!
.写法:
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写法:
Sub Page_Load() Sub Page_Load( ByVal sender As Object,ByVal e As System.EventArgs) Handles @H_792_7@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中~!

大佬总结

以上是大佬教程为你收集整理的vb.net 实现dropdownlist二级无刷新联动~!全部内容,希望文章能够帮你解决vb.net 实现dropdownlist二级无刷新联动~!所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。