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 9:45 PM
 

I see. It just seems odd that you would have a "loop" inside the  "rptSpeakerDirectory_ItemDataBound" method. That method is being called for each item (or row) that is bound to the Repeater (or ListView). Putting a loop inside that method is is like saying:

"For each person that you are about to display, call this stored procedure and get all these items each time"

Thats fine if that is what you want. But you indicated that you were not getting what you wanted. Perhaps this is where the problem lies?



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
4/10/2008 1:28 PM
 

You're absolutely right that my logic in the itemdatabound method is wrong.

The idea is there are columns that need to be formatted/concat for display and I would do so at this event. Like, I call FormatNameString and send it first, last, middle, and suffix which determines if suffix and/or middle initial is null (first and last can't be null) and then concats the string correctly. So in my ItemDataBound method I would retrieve those rows from Linq and then send them into the FormatNameString function, which returns nameString, and then I display that on the page.

I should note, there is no requirement to use a Repeater. So with the ListView and using your example, how would I get these items from the current row in itemdatabound?

 
New Post
4/10/2008 4:51 PM
Accepted Answer 

Fixed...finally clicked that one of the beauties of LINQ is the reduced amount of code monkeying we have to do. So to summarize I really didn't need to have an ItemDataBound event at all to grab the values coming back from the database calls. Instead I just call my formatting functions from my ascx and it works beautifu

 

<asp:LinqDataSource ID="lnkViewSpkrDir" runat="server" ContextTypeName="GovernanceInstitute.Modules.SpeakerDirectory.DirectoryDataContext"
    OrderBy="LastName" TableName="TGIDirectories">
</asp:LinqDataSource>
<asp:ListView ID="lstDirectory" runat="server" DataKeyNames="ItemID" DataSourceID="lnkViewSpkrDir">
    <LayoutTemplate>
        <table runat="server">
            <tr runat="server">
                <td runat="server">
                    <table id="itemPlaceholderContainer" runat="server" border="0" style="">
                        <tr id="itemPlaceholder" runat="server">
                        </tr>
                    </table>
                </td>
            </tr>
            <tr runat="server">
                <td runat="server" style="">
                    <asp:DataPager ID="lstDirectoryPager" runat="server" PageSize="5">
                        <Fields>
                            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False"
                                ShowPreviousPageButton="False" />
                            <asp:NumericPagerField />
                            <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False"
                                ShowPreviousPageButton="False" />
                        </Fields>
                    </asp:DataPager>
                </td>
            </tr>
        </table>
    </LayoutTemplate>
    <EmptyDataTemplate>
        <table runat="server" style="">
            <tr>
                <td>
                    No data was returned.
                </td>
            </tr>
        </table>
    </EmptyDataTemplate>
    <ItemTemplate>
        <tr>
            <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='<%# FormatNameString(Eval("firstName"),Eval("middleInitial"),Eval("lastName"),Eval("suffix")) %>'
                    CommandName="lnkFullName_Link" CommandArgument='<%# Eval("itemID")%>' OnClick="lnkFullName_Click"></asp:LinkButton><br />
                <asp:Label ID="lblCityState" runat="server" Text='<%# FormatCityState(Eval("city"),Eval("State")) %>'
                    SkinID="lblCityState" />
            </td>
            <td align="left">
                <asp:Label ID="lblBio" runat="server" Text='<%# Shorten(Eval("Biography"), 200) %>' />
            </td>
        </tr>
    </ItemTemplate>
</asp:ListView>

 

Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports DotNetNuke
Imports DotNetNuke.Security
Imports DotNetNuke.Entities.Modules

Namespace Modules.SpeakerDirectory
    Partial Public Class ViewDirectory
        Inherits DotNetNuke.Entities.Modules.PortalModuleBase


#Region "Event Handlers"

        Protected Sub lnkFullName_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim objlnkFullName As LinkButton = sender
            Response.Redirect(NavigateURL(PortalSettings.ActiveTab.TabID, "viewspeaker", "mid=" & CStr(ModuleId), "itemid=" & objlnkFullName.CommandArgument))

        End Sub

        Protected Sub lnkViewSpkrDir_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs)
            e.WhereParameters("ModuleId") = ModuleId
        End Sub

        Public Function FormatCityState(ByVal city As String, ByVal state As String) As String
            Dim locString 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
            Dim namestring 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

    End Class
End Namespace

 
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