+ Reply to Thread
Results 1 to 7 of 7

Thread: Binding data...

  1. #1
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Binding data...

    hi

    i'm gonna start binding data myself instead of using the DataSource control.
    so this is my thread to get help on all my upcoming issues

    Please remember i'm a n00b, so no .Net jargon, simple terms please

    first off I want to populate a Repeater control with a list of records, i have
    created all the necessary code for a list in my App_code under the relevant
    layers.

    so first of all my aspx page:
    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="projects.aspx.vb" Inherits="view_projects" MasterPageFile="Default.master" %>
    <asp:content id="projects" contentplaceholderid="ContentContainer" runat="server">
        <div>
            <asp:Repeater ID="rpProjectsList" runat="server">
            </asp:Repeater>
        </div>
    </asp:content>
    
    my aspx.vb:
    Code:
    Imports Keith.ProjectManager.BLL
    
    Partial Class view_projects
        Inherits System.Web.UI.Page
    
        Sub Page_Load()
            If Not IsPostBack Then
                dsProjectList()
            End If
        End Sub
    
        Public Sub dsProjectList()
            Dim dsProjectList As New DataList
            dsProjectList.DataSource = ProjectsManager.GetList()
            dsProjectList.DataBind()
        End Sub
    
    End Class
    
    is that correct? or did i miss something?
    Shem

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I don't think it's quite right.

    You need to create a List class in your BOL, create an instance of this class in your code and then fill this with data usnig your GetList BLL function.

    Something like:-
    .aspx
    Code:
    <asp:repeater id="repeater1" runat="server">
    <ItemTemplate>
    <tr><td>
    <%#Eval("firstname")%>
    </td>
    <td>
    <%#Eval("surname")%>
    </td>
    </tr>
    </ItemTemplate>
    </asp:repeater>
    
    BOL
    Code:
    Imports System.Collections.Generic
     
    Public Class UserList
            Inherits List(Of User)
            Sub New()
            End Sub
    End Class
     
    Public Class User
         Private _firstname As String = String.Empty
         Public Property firstname() As String
             Get
                   Return _firstname
             End Get
             Set (ByVal value As String)
                    _firstname = value
             End Set
          End Property
     
         Private _surname As String = String.Empty
         Public Property surname() As String
             Get
                   Return _surname
             End Get
             Set (ByVal value As String)
                    _surname= value
             End Set
          End Property
     
    End Class
    
    Then to bind the data use
    Code:
    Dim userlist as New UserList
    userlist = UserBLL.GetList()
    repeater1.DataSource=userlist
    repeater1.DataBind()
    
    Where your GetList function returns a UserList object

    Hope that makes sense.
    Last edited by richyrich; July 7th, 2008 at 06:16 AM.

  3. #3
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    I have built all that already..

    here's my code for projects list:
    DAL:
    Code:
    Public Shared Function GetList() As ProjectsList
                Dim tempList As ProjectsList = Nothing
                'Using
                Dim myConnection As MySqlConnection = New MySqlConnection(myConfig.myConnection)
                Try
                    Dim myCommand = New MySqlCommand(QueryProjectsDB.Projects(), myConnection)
                    myConnection.Open()
                    ' Using
                    Dim myReader As MySqlDataReader = myCommand.ExecuteReader
                    Try
                        If myReader.HasRows Then
                            tempList = New ProjectsList
                            While myReader.Read
                                tempList.Add(FillDataRecord(myReader))
                            End While
                        End If
                        myReader.Close()
                    Finally
                        CType(myReader, IDisposable).Dispose()
                    End Try
                Finally
                    CType(myConnection, IDisposable).Dispose()
                End Try
                Return tempList
            End Function
    
    Private Shared Function FillDataRecord(ByVal myDataRecord As IDataRecord) As Projects
                Dim myProjects As Projects = New Projects
                myProjects.Idkey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("idkey"))
                myProjects.TheDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("pdate"))
                myProjects.Name = myDataRecord.GetString(myDataRecord.GetOrdinal("name"))
                myProjects.ProjectNumber = myDataRecord.GetString(myDataRecord.GetOrdinal("number"))
                myProjects.Description = myDataRecord.GetString(myDataRecord.GetOrdinal("description"))
                myProjects.UserID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("userid"))
                myProjects.Edited = myDataRecord.GetInt32(myDataRecord.GetOrdinal("edited"))
                Return myProjects
            End Function
    
    BOL:
    Code:
    Public Class Projects
    
            Private _idkey As Nullable(Of Integer)
            Private _edited_id As Nullable(Of Integer)
            Private _user_id As Nullable(Of Integer)
            Private _date As Nullable(Of Date)
            Private _name As String = String.Empty
            Private _number As String = String.Empty
            Private _description As String = String.Empty
    
            <DataObjectFieldAttribute(True, True, False)> _
            Public Property Idkey() As Integer
                Get
                    Return _idkey
                End Get
                Set(ByVal value As Integer)
                    _idkey = value
                End Set
            End Property
    
            Public Property Edited() As Integer
                Get
                    Return _edited_id
                End Get
                Set(ByVal value As Integer)
                    _edited_id = value
                End Set
            End Property
    
            Public Property UserID() As Integer
                Get
                    Return _user_id
                End Get
                Set(ByVal value As Integer)
                    _user_id = value
                End Set
            End Property
    		
            Public Property TheDate() As Date
                Get
                    Return _date
                End Get
                Set(ByVal value As Date)
                    _date = value
                End Set
            End Property
    		
            Public Property Name() As String
                Get
                    Return _name
                End Get
                Set(ByVal value As String)
                    _name = value
                End Set
    		End Property
    		
            Public Property ProjectNumber() As String
                Get
                    Return _number
                End Get
                Set(ByVal value As String)
                    _number = value
                End Set
            End Property
    		
            Public Property Description() As String
                Get
                    Return _description
                End Get
                Set(ByVal value As String)
                    _description = value
                End Set
            End Property
    		
        End Class
    
    In my BOL i have a collections folder:
    Code:
    Public Class ProjectsList
    
            Inherits List(Of Projects)
    
            Public Sub New()
            End Sub
    
        End Class
    
    BLL:
    Code:
    <DataObjectMethod(DataObjectMethodType.Select, True)> _
            Public Shared Function GetList() As ProjectsList
                Return ProjectsDB.GetList()
            End Function
    
    So as far as i thought, all i need to do is call BLL - GetList()?

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I believe you should create an instance of ProjectsList first and fill it with data using the GetList BLL function.

    Code:
    Dim ProjectsList As New ProjectsList
    ProjectsList = BLL.GetList()
     
    repeaterid.DataSource = ProjectsList
    repeaterid.DataBind()
    
    Then you can use the properties of a Projects class (Idkey, Edited etc.) in your repeater.

  5. #5
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    my aspx:
    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="projects.aspx.vb" Inherits="view_projects" MasterPageFile="Default.master" %>
    <asp:content id="projects" contentplaceholderid="ContentContainer" runat="server">
        <div>
            <asp:Repeater ID="rpProjectList" runat="server">
                <ItemTemplate>
                    <p>
                        Test
                    </p>
                </ItemTemplate>
            </asp:Repeater>
        </div>
    </asp:content>
    
    aspx.vb:
    Code:
    Imports Keith.ProjectManager.BLL
    Imports Keith.ProjectManager.BO
    
    Partial Class view_projects
        Inherits System.Web.UI.Page
    
        Sub Page_Load()
            'If Not IsPostBack Then
            Dim ProjectsList As New ProjectsList
            ProjectsList = ProjectsManager.GetList()
    
            rpProjectList.DataSource = ProjectsList
            rpProjectList.DataBind()
            'End If
        End Sub
    
    End Class
    
    so it should repeat the text "Test"? but it doesn't

  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Yes. It should repeat Test for however many items are in your List.

    Could you try setting AutoEventWireup to True, or remove it in your page? I'm not sure if you set it to false whether you have to explicitly define all the page events.

    Just a quick check.

  7. #7
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    working now
    thanx a stack RR

+ Reply to Thread

Similar Threads

  1. Replies: 5
    Last Post: June 25th, 2008, 09:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO