Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

telerik -- supercharge your DNN websites
  Ads  
OnyakTech
 


  Sponsors  

Meet Our Sponsors

SmarterTools
Verndale
The Official Microsoft ASP.NET Website
Portal Webhosting - Hosting For Developers
Red-Gate Software
MaximumASP
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! (Pro...  Repeater does too good of a job (using LINQ)
Previous Previous
 
Next Next
New Post 4/9/2008 11:32 AM
Resolved
User is offline toadkicker
30 posts
10th Ranked


Repeater does too good of a job (using LINQ) 

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 1:29 PM
User is offline Michael Washington
2848 posts
ADefWebserver.com
5th Ranked










Re: Repeater does too good of a job (using LINQ) 
Modified By Michael Washington  on 4/9/2008 4:04:26 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
* ADefWebserver.com
* DNN Module Developer's Guide
* IWEB - DNN Web Services
* Silverlight and DotNetNuke
 
New Post 4/9/2008 4:59 PM
User is offline toadkicker
30 posts
10th Ranked


Re: Repeater does too good of a job (using LINQ) 

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 5:51 PM
User is offline Michael Washington
2848 posts
ADefWebserver.com
5th Ranked










Re: Repeater does too good of a job (using LINQ) 

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
* ADefWebserver.com
* DNN Module Developer's Guide
* IWEB - DNN Web Services
* Silverlight and DotNetNuke
 
New Post 4/9/2008 6:53 PM
User is offline toadkicker
30 posts
10th Ranked


Re: Repeater does too good of a job (using LINQ) 

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 Previous
 
Next Next
  Forum  General DotNetN...  Extend It! (Pro...  Repeater does too good of a job (using LINQ)
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, 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 DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


DNNMasters - modules, consulting, development
DNNMasters developers are involved in DNN development since DNN 1.0.9 and today we offer a broad range of DNN related products and services including custom development of modules, help with ing third party modules for specific needs, general DNN technical support and administrative services.
www.dnnmasters.com
Cygnusoft Custom Software
Cygnusoft has been providing cutting-edge custom software solutions for 20 years. Cygnusoft is also a leading start-up incubator, helping our partners build successful new businesses.
www.cygnusoft.com
Digicon: DotNetNuke design and development
Digicon is based in Brisbane, Queensland, Australia
digicon.com.au

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP