组件 DataList 和 ObjectDataSource

功能强大的组件。我这里主要介绍一下
asp.net 端的代码:
 
 
ContractedBlock.gif ExpandedBlockStart.gif Code
 1                  <asp:DataList id="dlstProducts" DataSourceID="srcProducts" RepeatColumns="1" Runat="server">
 2                      <ItemTemplate>  
 3ExpandedBlockStart.gifContractedBlock.gif                           Property ()Property<%#IIf(CType(Eval("Manynumber"), Integer> 1"&nbsp;" & Eval("Numberproperyies"& "&nbsp;""&nbsp;")%>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 的类
 
ContractedBlock.gif ExpandedBlockStart.gif 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 IntegerAs 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

 

这些代码是 帮助理解, 做个小测试。

转载于:https://www.cnblogs.com/sandy_liao/archive/2008/12/12/1353943.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值