ASP+中取代ASP的RS(Remote Scripting)技术的Framework,ASP+中取代ASP的RS(Remote Scripting)技术的Framework
【 tulaoshi.com - ASP.NET 】
在上面的文章里面我提到了Page.IsPostBack属性的一个应用,可以用来保存用户输入的Products.aspx代码如下:
<%@ Import Namespace="System.Data"%
<%@ Import Namespace="System.Data.ADO"%
<script language="VB" runat="server"
Sub Page_Load (SourceObj as Object, EveArg as EventArgs)
If Not Page.IsPostBack Then
Dim mudCommand As ADODataSetCommand
Dim mudConnection As ADOConnection
Dim dSet As New DataSet
Dim strSQL as String
Dim connStr as String
strSQL = "SELECT CategoryID, CategoryName From Categories"
connStr = "Provider = SQLOLEDB; Data Source=test; Initial Catalog=Northwind; User ID=sa; password=;"
mudConnection = New ADOConnection(connStr)
mudCommand = New ADODataSetCommand(strSQL, mudConnection)
mudCommand.FillDataSet(dSet, "Categories")
mudCategories.DataSource = dSet.Tables("Categories").DefaultView
mudCategories.DataBind()
End If
End Sub
Sub displayProducts (Source as Object, EveArg as EventArgs)
Dim mudCommand As ADODataSetCommand
Dim mudConnection As ADOConnection
Dim dSet As New DataSet
Dim strSQL as String
Dim connStr as String
connStr = "Provider = SQLOLEDB; Data Source=test; Initial Catalog=Northwind; User ID=sa; password=;"
strSQL = "Select ProductID, ProductName From Products"
strSQL = strSQL & " WHERE CategoryID = " & mudCategories.SelectedItem.Value
mudConnection = New ADOConnection(connStr)
mudCommand = New ADODataSetCommand(strSQL, mudConnection)
mudCommand.FillDataSet(dSet, "Products")
mudProducts.DataSource = dSet.Tables("Products").DefaultView
mudProducts.DataBind()
End Sub
</script
<html
<form name="mudForm" runat="server"
产品目录:
<asp:DropDownList id="mudCategories" runat="server" DataTextField="CategoryName" DataValueField="CategoryID" AutoPostBack="true" OnSelectedIndexChanged="displayProducts"/
产品: <asp:ListBox id="mudProducts" SelectionMode="Multiple" DataValueField="ProductID" DataTextField="ProductName" runat="server" /
</html
从例子程序可以看到,其中显然是使用了服务器端控件的下拉框OnChange事件配合AutoPostBack和
Page.IsPostBack属性就可以很简单和清晰的实现了以前在asp中烦琐的RS实现方法。
呵呵,希望大家从上面的这个例子中有所收获。
来源:http://www.tulaoshi.com/n/20160129/1492064.html
看过《ASP+中取代ASP的RS(Remote Scripting)技术的Framework》的人还看了以下文章 更多>>