功能强大的组件。我这里主要介绍一下
asp.net 端的代码:
Code
1 <asp:DataList id="dlstProducts" DataSourceID="srcProducts" RepeatColumns="1" Runat="server">
2 <ItemTemplate>
3 Property ()Property<%#IIf(CType(Eval("Manynumber"), Integer) > 1, " " & Eval("Numberproperyies") & " ", " ")%>details
4 <br /><br />
5 <asp:Label ID="dizhi" runat="server" Text="di zhi : " CssClass="title2"></asp:Label>
6 <%#Eval("dizhi")%></span>
7 <br /><br />
8 <asp:Label ID="youbian" runat="server" Text="you bian: " CssClass="title2"></asp:Label>
9 <%#Eval("youbian")%>
10 <br /><br />
11 <asp:Label ID="jiage1" runat="server" Text="jia ge 1 : " CssClass="title2"></asp:Label>
12 <%#String.Format("{0:c}", Eval("jiage1"))%>
13 <br /><br />
14 <asp:Label ID="jiage2" runat="server" Text="jia ge 2 : " CssClass="title2"></asp:Label>
15 <%#IIf(Eval("jiage2") = 0, "", String.Format("{0:c}", Eval("Contentsvalue"))) & "<br /><br />"%>
16 </ItemTemplate>
17 </asp:DataList>
18
19 <asp:ObjectDataSource id="srcProducts"
20 TypeName="xxx.xxxxClass"
21 SelectMethod="SelectCustomerId" Runat="server" OnSelecting="srcProducts_Selecting">
22 <SelectParameters>
23 <asp:Parameter Name="CustomerID" Type="Int32" />
24 </SelectParameters>
25 </asp:ObjectDataSource>
1 <asp:DataList id="dlstProducts" DataSourceID="srcProducts" RepeatColumns="1" Runat="server">
2 <ItemTemplate>
3 Property ()Property<%#IIf(CType(Eval("Manynumber"), Integer) > 1, " " & Eval("Numberproperyies") & " ", " ")%>details
4 <br /><br />
5 <asp:Label ID="dizhi" runat="server" Text="di zhi : " CssClass="title2"></asp:Label>
6 <%#Eval("dizhi")%></span>
7 <br /><br />
8 <asp:Label ID="youbian" runat="server" Text="you bian: " CssClass="title2"></asp:Label>
9 <%#Eval("youbian")%>
10 <br /><br />
11 <asp:Label ID="jiage1" runat="server" Text="jia ge 1 : " CssClass="title2"></asp:Label>
12 <%#String.Format("{0:c}", Eval("jiage1"))%>
13 <br /><br />
14 <asp:Label ID="jiage2" runat="server" Text="jia ge 2 : " CssClass="title2"></asp:Label>
15 <%#IIf(Eval("jiage2") = 0, "", String.Format("{0:c}", Eval("Contentsvalue"))) & "<br /><br />"%>
16 </ItemTemplate>
17 </asp:DataList>
18
19 <asp:ObjectDataSource id="srcProducts"
20 TypeName="xxx.xxxxClass"
21 SelectMethod="SelectCustomerId" Runat="server" OnSelecting="srcProducts_Selecting">
22 <SelectParameters>
23 <asp:Parameter Name="CustomerID" Type="Int32" />
24 </SelectParameters>
25 </asp:ObjectDataSource>
app_code 的类
Code
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports System.Collections.Generic
Namespace xxxx
''' <summary>
''' Represents a product and methods for
''' working with products
''' </summary>
Public Class xxxxClass
Private Shared ReadOnly _connectionString As String
Private _id As Integer
Private _manynumber As Integer
Private _dizhi As String
Private _youbian As String
Private _jiage1 As Decimal
Private _jiage2 As Decimal
Private _number As String
Public Property Id() As Integer
Get
Return _id
End Get
Set(ByVal Value As Integer)
_id = Value
End Set
End Property
Public Property dizhi() As String
Get
Return _dizhi
End Get
Set(ByVal Value As String)
_dizhi = Value
End Set
End Property
Public Property Number() As String
Get
Return _number
End Get
Set(ByVal Value As String)
_number = Value
End Set
End Property
Public Property youbian() As String
Get
Return _youbian
End Get
Set(ByVal Value As String)
_youbian = Value
End Set
End Property
Public Property jiage1() As Decimal
Get
Return _jiage1
End Get
Set(ByVal Value As Decimal)
_jiage1 = Value
End Set
End Property
Public Property jiage2() As Decimal
Get
Return _jiag2
End Get
Set(ByVal Value As Decimal)
_jiage2 = Value
End Set
End Property
''' <summary>
''' Select all products in a particular category
''' </summary>
'''
Public Shared Function SelectCustomerId(ByVal CustomerID As Integer) As List(Of xxxxClass)
' Initialize command
Dim con As New SqlConnection(_connectionString)
Dim cmd As New SqlCommand("xxxxxSelectByCustomerId", con)
cmd.CommandType = CommandType.StoredProcedure
' Add parameters
cmd.Parameters.AddWithValue("@CustomerID", CustomerID)
Dim results As New List(Of PropertyClass)()
Using con
con.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read()
results.Add(New xxxxClass(reader))
End While
End Using
Return results
End Function
''' <summary>
''' Initializes a product from a DataReader
''' </summary>
Public Sub New(ByVal reader As SqlDataReader)
_id = CType(reader("CustomerID"), Integer)
_dizhi= CType(reader("dizhi"), String)
_youbian= CType(reader("youbian"), String)
_jiage1= CType(reader("jiage1"), Decimal)
_jiage2= CType(reader("jiage2"), Decimal)
_manynumber = CType(reader("manynumber "), Integer)
End Sub
''' <summary>
''' Retrieve database connection string from Web configuration
''' </summary>
Shared Sub New()
_connectionString = "data source=sdd,user name=xxx, password=xxxx"
End Sub
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports System.Collections.Generic
Namespace xxxx
''' <summary>
''' Represents a product and methods for
''' working with products
''' </summary>
Public Class xxxxClass
Private Shared ReadOnly _connectionString As String
Private _id As Integer
Private _manynumber As Integer
Private _dizhi As String
Private _youbian As String
Private _jiage1 As Decimal
Private _jiage2 As Decimal
Private _number As String
Public Property Id() As Integer
Get
Return _id
End Get
Set(ByVal Value As Integer)
_id = Value
End Set
End Property
Public Property dizhi() As String
Get
Return _dizhi
End Get
Set(ByVal Value As String)
_dizhi = Value
End Set
End Property
Public Property Number() As String
Get
Return _number
End Get
Set(ByVal Value As String)
_number = Value
End Set
End Property
Public Property youbian() As String
Get
Return _youbian
End Get
Set(ByVal Value As String)
_youbian = Value
End Set
End Property
Public Property jiage1() As Decimal
Get
Return _jiage1
End Get
Set(ByVal Value As Decimal)
_jiage1 = Value
End Set
End Property
Public Property jiage2() As Decimal
Get
Return _jiag2
End Get
Set(ByVal Value As Decimal)
_jiage2 = Value
End Set
End Property
''' <summary>
''' Select all products in a particular category
''' </summary>
'''
Public Shared Function SelectCustomerId(ByVal CustomerID As Integer) As List(Of xxxxClass)
' Initialize command
Dim con As New SqlConnection(_connectionString)
Dim cmd As New SqlCommand("xxxxxSelectByCustomerId", con)
cmd.CommandType = CommandType.StoredProcedure
' Add parameters
cmd.Parameters.AddWithValue("@CustomerID", CustomerID)
Dim results As New List(Of PropertyClass)()
Using con
con.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read()
results.Add(New xxxxClass(reader))
End While
End Using
Return results
End Function
''' <summary>
''' Initializes a product from a DataReader
''' </summary>
Public Sub New(ByVal reader As SqlDataReader)
_id = CType(reader("CustomerID"), Integer)
_dizhi= CType(reader("dizhi"), String)
_youbian= CType(reader("youbian"), String)
_jiage1= CType(reader("jiage1"), Decimal)
_jiage2= CType(reader("jiage2"), Decimal)
_manynumber = CType(reader("manynumber "), Integer)
End Sub
''' <summary>
''' Retrieve database connection string from Web configuration
''' </summary>
Shared Sub New()
_connectionString = "data source=sdd,user name=xxx, password=xxxx"
End Sub
End Class
End Namespace
这些代码是 帮助理解, 做个小测试。