Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Binding data..." in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 7th, 2008, 04:58 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default 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
Reply With Quote
Sponsored Links
  #2  
Old July 7th, 2008, 05:14 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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 05:16 AM.
Reply With Quote
  #3  
Old July 7th, 2008, 05:24 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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()?
Reply With Quote
  #4  
Old July 7th, 2008, 05:50 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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.
Reply With Quote
  #5  
Old July 7th, 2008, 06:05 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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
Reply With Quote
  #6  
Old July 7th, 2008, 06:21 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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.
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
Shem (July 7th, 2008)
  #7  
Old July 7th, 2008, 07:06 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

working now
thanx a stack RR
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The data source 'ObjectDataSource1' does not support sorting with IEnumerable data Shem .Net Development 5 June 25th, 2008 08:07 AM


All times are GMT -4. The time now is 03:55 PM.



Content Relevant URLs by vBSEO 3.2.0