Use generic List as the data source of ListView control

1. The front aspx page should be setup as below.

</pre>
<table id="Table1" style="width: 550px;" width="550" border="0" cellspacing="1" cellpadding="3">
<tbody>
<tr>
<td><strong>108 seats total:</strong></td>
<td> </td>
</tr>
<tr>
<th>Party Name</th>
<th>Seats</th>
<th>website</th>
</tr>
</tbody>
</table>
<pre>   

2. setup a class and fill the generic list with that objects.

    Private Class partyinfo
        Dim _partyname As String
        Dim _seats As String
        Dim _weblink_desc As String
        Dim _weblink_url As String
        Dim _seatnumber As Integer

        Public Property partyname() As String
            Get
                Return _partyname
            End Get
            Set(ByVal value As String)
                _partyname = value
            End Set
        End Property

        Public Property seats() As String
            Get
                Return _seats
            End Get
            Set(ByVal value As String)
                _seats = value
            End Set
        End Property

        Public Property seatnumber() As Integer
            Get
                Return _seatnumber
            End Get
            Set(ByVal value As Integer)
                _seatnumber = value
            End Set
        End Property

        Public Property weblink_desc() As String
            Get
                Return _weblink_desc
            End Get
            Set(ByVal value As String)
                _weblink_desc = value
            End Set
        End Property

        Public Property weblink_url() As String
            Get
                Return _weblink_url
            End Get
            Set(ByVal value As String)
                _weblink_url = value
            End Set
        End Property

        Public Sub partyinfo()
            _partyname = String.Empty
            _seats = String.Empty
            _weblink_desc = String.Empty
            _weblink_url = String.Empty
        End Sub

    End Class

    Private Function getPartyData(ByVal legidstr As String) As List(Of partyinfo)

        Try
            Dim arrlist As New ArrayList
            Dim LegID As Integer = Convert.ToInt16(legidstr)
            arrlist = cl_mla.mla.load_PartySeats(LegID)
            Dim mylist As New List(Of partyinfo)

            If arrlist.Count > 0 Then
                For i As Integer = 0 To arrlist.Count - 1
                    Dim myMLA As New cl_mla.mla
                    myMLA = CType(arrlist(i), cl_mla.mla)

                    Dim myitem As New partyinfo()
                    If myMLA.PartySeats > 1 Then
                        myitem.seats = myMLA.PartySeats.ToString + "  seats"
                    Else
                        myitem.seats = myMLA.PartySeats.ToString + "  seat"
                    End If

                    myitem.seatnumber = myMLA.PartySeats
					.........................................................
					.........................................................
                    If myitem.seatnumber > 0 Then
                        mylist.Add(myitem)
                    End If

                Next
            End If

            Return mylist

        Catch ex As Exception
            Return Nothing
        End Try

    End Function

3.  bind data to the list

            lstvw_party.DataSource = getPartyData(ConfigurationManager.AppSettings("xx_id"))
            lstvw_party.DataBind()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s