Hello,
I am building what is basically an address book module using a repeater control. When I step through the code, I see that it correctly pulls the records in order, but the output is only the last record. Stumped and out of google search options, I'm hoping that someone can shed some light on my error and help someone else out in the future.
Also any general feedback on coding standards is welcome...what do I know other than not much =D
<asp:Repeater ID="rptSpeakerDirectory" runat="server" DataSourceID="lnkViewSpkrDir">
<HeaderTemplate>
<table cellpadding="5px" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td id="colitemid"><asp:Label runat="server" Text='<%# itemid %>' /></td>
<td width="120px">
<!-- put in logic to check if imagepath is null, and if so hide control -->
<asp:Image ID="imgSpeaker" runat="server" ImageUrl='<%# Bind(Container.DataItem, "imagePath") %>'
Height="150px" Width="100px" />
</td>
<td align="left" width="120px">
<asp:LinkButton ID="lnkFullName" runat="server" Text='<%# nameString %>' CommandName="lnkFullName_Link"
CommandArgument="itemID"></asp:LinkButton><br />
<asp:Label ID="lblCityState" runat="server" Text='<%# locString %>' SkinID="lblCityState" />
</td>
<td align="left">
<asp:Label ID="lblBio" runat="server" Text='<%# itemBio %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
and the VB:
Partial Public Class ViewDirectory
Inherits DotNetNuke.Entities.Modules.PortalModuleBase
Implements IActionable
#Region "Private Properties"
Private _nameString As String
Private _imagePath As String
Private _itemID As Integer
Private _itemBio As String
Private intSortID As Integer
Private currentPageNumber As Integer = 1
Private _locString As String
#End Region
#Region "Public Properties"
Public Property itemBio() As String
Get
Return _itemBio
End Get
Set(ByVal value As String)
_itemBio = value
End Set
End Property
Public Property itemID() As Integer
Get
Return _itemID
End Get
Set(ByVal value As Integer)
_itemID = value
End Set
End Property
Public Property nameString() As String
Get
Return _nameString
End Get
Set(ByVal Value As String)
_nameString = Value
End Set
End Property
Public Property locString() As String
Get
Return _locString
End Get
Set(ByVal value As String)
_locString = value
End Set
End Property
Public Property imagePath() As String
Get
Return _imagePath
End Get
Set(ByVal value As String)
_imagePath = value
End Set
End Property
#End Region
#Region "Event Handlers"
'Private Sub Page_Load(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Load
' Try
' rptSpeakerDirectory.DataBind()
' Catch ex As Exception
' Exceptions.ProcessModuleLoadException(Me, ex)
' End Try
'End Sub
Protected Sub lnkFullName_LinkItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs) Handles rptSpeakerDirectory.ItemCommand
If e.CommandName Is "lnkFullName_Link" Then
Response.Redirect(NavigateURL(PortalSettings.ActiveTab.TabID, "viewspeaker", "mid=" & CStr(ModuleId), "itemid=" & CStr(itemID)))
End If
End Sub
'Protected Sub rptSpeakerDirectory_RowCommand(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles rptSpeakerDirectory.ItemDataBound
' 'Find the link, create it, and tell it to redirect to the "ViewSpeaker" control with the right itemID
' Dim strLinkID As String
' If e.Item Is lnkViewSpkrDir Then
' strLinkID = rptSpeakerDirectory.Controls(Convert.ToInt32(e.Item("itemID")).ToString)
' Dim objModules As Entities.Modules.ModuleController = New Entities.Modules.ModuleController
' Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(PortalSettings.ActiveTab.TabID, Null.NullString, "ID=" & strLinkID))
' End If
'End Sub
'Protected Sub lnqSpeakerData_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs) Handles lnkViewSpkrDir.Selecting
' e.WhereParameters("ModuleId") = ModuleId
'End Sub
Protected Sub rptSpeakerDirectory_ItemDataBound(ByVal sender As Object, ByVal e As EventArgs) Handles rptSpeakerDirectory.DataBinding
nameString = ""
'Dim curItemID = From itemid In results Select itemid
'Dim itemid As Integer = CType(DataBinder.Eval(e.Item.DataItem, "itemID"), Integer)
Dim directorydata As New DirectoryDataContext
Dim speakers = directorydata.GetSpeakerDirectories()
For Each speakerrecord In speakers
itemID = speakerrecord.ItemID
Dim imagePath = speakerrecord.ImagePath
Dim City = speakerrecord.City
Dim State = speakerrecord.State
Dim First = speakerrecord.FirstName
Dim MInitial = speakerrecord.MiddleInitial
Dim Last = speakerrecord.LastName
Dim Suffix = speakerrecord.suffix
Dim Biography = speakerrecord.Biography
Dim companyURL = speakerrecord.CompanyURL
'Format the person's name
FormatNameString(First, Last, MInitial, Suffix)
'fix url's
companyURL = GetURL(companyURL)
'Shorten up the bio
Biography = Shorten(Biography, 200)
itemBio = Biography
'Format for city and state
FormatCityState(City, State)
'Build Speaker Name Link
'?? maybe
'beginings of removing empty images
'If String.IsNullOrEmpty(imagePath) Then
' Dim findimgSpeaker As Image
' Dim chkimgSpeaker As Image = findimgSpeaker.FindControl("imgSpeaker")
' chkimgSpeaker.Visible = False
'End If
Next
End Sub
Public Function CheckIfImageIsNullOrEmpty(ByVal imagePath As String, ByVal sender As Object, ByVal e As EventArgs) As String
If String.IsNullOrEmpty(imagePath) Then
Dim curimage = rptSpeakerDirectory.FindControl("imgSpeaker")
End If
End Function
Public Function FormatCityState(ByVal city As String, ByVal state As String) As String
If String.IsNullOrEmpty(city) Then
If String.IsNullOrEmpty(state) Then
locString = "City and State not in our database"
End If
ElseIf locString = city.Trim Then
Else
locString = city.Trim & ", " & state.Trim
End If
Return locString
End Function
Public Function FormatNameString(ByVal first As String, ByVal last As String, ByVal minitial As String, ByVal suffix As String) As String
If String.IsNullOrEmpty(suffix) Then
If String.IsNullOrEmpty(minitial) Then
nameString = first & " " & last
End If
nameString = first & " " & minitial & ". " & last
Else
nameString = first & " " & minitial & ". " & last & ", " & suffix
End If
Return nameString
End Function
Public Function GetURL(ByVal fldval As String) As String
If InStr(fldval, "http://") Then
Return fldval
ElseIf fldval = "" Then
Return ""
ElseIf String.IsNullOrEmpty(fldval) Then
Return ""
Else
Return "http://" & fldval
End If
End Function
Function Shorten(ByVal sString As String, ByVal sLength As Integer) As String
If Len(sString) > sLength Then
Shorten = Left(sString, sLength) & "...."
Else
Shorten = sString
End If
End Function
#End Region