说说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>
< 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));
}
}
{
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]类型
vb.net写法:
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
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
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