![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| 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>
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
Shem |
| Sponsored Links |
|
#2
| ||||
| ||||
| 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>
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
Code: Dim userlist as New UserList userlist = UserBLL.GetList() repeater1.DataSource=userlist repeater1.DataBind() Hope that makes sense. Last edited by richyrich; July 7th, 2008 at 05:16 AM. |
|
#3
| ||||
| ||||
| 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
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
Code: Public Class ProjectsList
Inherits List(Of Projects)
Public Sub New()
End Sub
End Class
Code: <DataObjectMethod(DataObjectMethodType.Select, True)> _
Public Shared Function GetList() As ProjectsList
Return ProjectsDB.GetList()
End Function
|
|
#4
| ||||
| ||||
| 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() |
|
#5
| ||||
| ||||
| 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>
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
|
|
#6
| ||||
| ||||
| 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. |
| The Following User Says Thank You to richyrich For This Useful Post: | ||
Shem (July 7th, 2008) | ||
|
#7
| ||||
| ||||
| working now ![]() thanx a stack RR |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
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 |