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  |  

AppTheory specializes in solutions based on the DotNetNuke platform and has 2 employees on the DotNetNuke Core Team.
  Need Help?  
Professional technical support for DotNetNuke is available from DotNetNuke Corporation.
 


  Ads  
OnyakTech
 


  Sponsors  

Meet Our Sponsors

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


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










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

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


Re: Repeater does too good of a job (using LINQ) 
Modified By toadkicker  on 4/10/2008 2:14:22 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 1:51 PM
Accepted Answer 
User is offline toadkicker
30 posts
10th Ranked


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

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 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.

 


Hosting for DotNetNuke
SiteGround.com is the best place to host your DotNetNuke website! Expert DotNetNuke support, reliable servers, low price!
www.SiteGround.com
Code Endeavors, LLC
Do you Endeavor to Enhance your DotNetNuke designs by utilizing AJAX technologies to more efficient interactive web experiences
www.codeendeavors.com
T-WORX, INC.
Professional DotNetNuke Solutions
www.t-worx.com

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