Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Repeater does too good of a job (using LINQ)Repeater does too good of a job (using LINQ)
Previous
 
Next
New Post
4/9/2008 1:32 PM
 

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

 

 
New Post
4/9/2008 3:29 PM
 

If you're using asp.net 3.5 you will want to use the ListView rather than the Repeater. See:

Creating a DotNetNuke Module using LINQ to SQL (C#) (Part 3)



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
4/9/2008 6:59 PM
 

Thanks Michael for your reply. I changed my control to a list view and recieved very similar results. The first record now shows an itemID of 0, the second and third show the same record. I am looking through your module code in the mean time but I wanted to give an update on what I changed and the results.

 

 
New Post
4/9/2008 7:51 PM
 

I am not sure what the

"For Each speakerrecord In speakers" loop

is doing in the "rptSpeakerDirectory_ItemDataBound" method

because the "rptSpeakerDirectory_ItemDataBound" fires for each record.

Perhaps you can describe what you are trying to do and we can suggest how we would do it. Also the example on my site should help.



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
4/9/2008 8:53 PM
 

GetSpeakerDirectories() is my SPROC being called in Linq

I used ScottGu's tutorial as a guide for writing this

http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx

The module has a viewall and a viewone control. The viewall control must pass itemid into the viewone via the URL because the company wants to be able to copy the URL and pull a specific person. I've been looking at your C# and I get most of it, but most of my experience thus far has been in VB.

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Repeater does too good of a job (using LINQ)Repeater does too good of a job (using LINQ)


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out