Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2004, 09:16 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Selective Display in Datalist

I have a Datalist that displays 3 columns of data. The first column, however should only display for the first row of a group. My logic is not producing the desired result as nothing is displayed in the first column. Here is my code:
Code:
Public curCenter As String = ""
.
.
.
Public Sub dlItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim CenterLabel As Label
            Select Case e.Item.ItemType
                Case ListItemType.Item
                    CenterLabel = CType(e.Item.FindControl("lblCenter"), Label)
                Case ListItemType.AlternatingItem
                    CenterLabel = CType(e.Item.FindControl("lblAltCenter"), Label)
            End Select

            If curCenter = CenterLabel.Text Then
                CenterLabel.Visible = False
            Else
                'new Center
                CenterLabel.Visible = True
            End If
            curCenter = CenterLabel.Text
        End If
    End Sub
I am at a loss to understand what's wrong. I welcome your comments.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old October 22nd, 2004, 10:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Probably this is always firing:

If curCenter = CenterLabel.Text Then
                CenterLabel.Visible = False

Out of curiosity, you check to see if curCenter is equal to the label text, but then later assign it. Wouldn't that create a group for all rows?

Could you post the data list code too?

Brian
 
Old October 22nd, 2004, 10:42 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Data List Code:
Code:
<asp:datalist id="dlListing" style="Z-INDEX: 107; LEFT: 0px; POSITION: absolute; TOP: 8px" runat="server"
                    OnItemDataBound="dlItemDataBound" Width="500">
                    <HeaderTemplate>
                        <TABLE id="Table2" cellSpacing="0" cellPadding="0" width="500" border="0">
                            <TR>
                                <TD width="30%">
                                    <asp:Label id="lblHeaderCenter" runat="server" CssClass="formlabel" Font-Bold="True">Center</asp:Label></TD>
                                <TD width="40%">
                                    <asp:Label id="lblHeaderCounselor" runat="server" CssClass="formlabel" Font-Bold="True">Counselor</asp:Label></TD>
                                <TD align="right" nowrap>
                                    <asp:Label id="lblHeaderCases" runat="server" CssClass="formlabel" Font-Bold="True">Number of Open Cases</asp:Label></TD>
                            </TR>
                        </TABLE>

                    </HeaderTemplate>
                    <ItemTemplate>
                        <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="500" border="0">
                            <TR>
                                <TD width="30%">
                                    <asp:Label id="lblCenter" runat="server" CssClass="formlabel" Font-Bold="True">
                                        <%# Container.DataItem("CenterName") %>
                                    </asp:Label></TD>
                                <TD width="40%">
                                    <asp:Label id="lblCounselor" runat="server" CssClass="formlabel">
                                        <%#Container.DataItem("Counselor")%>
                                    </asp:Label></TD>
                                <TD align="right">
                                    <asp:Label id="lblCases" runat="server" CssClass="formlabel">
                                        <%#FormatNumber(Container.DataItem("NumCases"), 0, , TriState.True)%>
                                    </asp:Label></TD>
                            </TR>
                        </TABLE>
                    </ItemTemplate>
                    <AlternatingItemTemplate>
                        <TABLE id="Table3" cellSpacing="0" cellPadding="0" width="500" border="0">
                            <TR bgColor="#dddddd">
                                <TD width="30%">
                                    <asp:Label id="lblAltCenter" runat="server" CssClass="formlabel" Font-Bold="True">
                                        <%# Container.DataItem("CenterName") %>
                                    </asp:Label></TD>
                                <TD width="40%">
                                    <asp:Label id="lblAltCounselor" runat="server" CssClass="formlabel">
                                        <%#Container.DataItem("Counselor")%>
                                    </asp:Label></TD>
                                <TD align="right">
                                    <asp:Label id="lblAltCases" runat="server" CssClass="formlabel">
                                        <%#FormatNumber(Container.DataItem("NumCases"), 0, , TriState.True)%>
                                    </asp:Label></TD>
                            </TR>
                        </TABLE>
                    </AlternatingItemTemplate>
                </asp:datalist>
The purpose behind the line:
Code:
curCenter = CenterLabel.Text
Is so that the Sub can "remember" what the Center value was for the previous row.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old October 22nd, 2004, 12:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Try changing your Container.DataItem("..") to Databinder.Eval(Container.DataItem, ".."). Also, bind them to the text property of the label, as such:

<asp:Label ... Text='<%# Databinder.Eval(Container.DataItem, "..") %>'>...

Brian

Brian
 
Old October 22nd, 2004, 12:32 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That did the trick, thank you very much!

I would like to know what the difference is between the Container.DataItem and Databinder.Eval methods. Is Databinder.Eval needed in order to respond to the ItemDataBound event?

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old October 25th, 2004, 07:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Don't really know. I've just always known to do Databinder.Eval. I've tried Container.DataItem directly and it didn't work for me.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
datalist display almotions ASP.NET 2.0 Basics 1 February 18th, 2008 03:19 AM
unable to display my datalist frresh C# 2005 0 November 14th, 2006 11:52 AM
How To Display Images in DataList abdul_owiusa General .NET 4 June 3rd, 2005 11:49 AM
How To Display Images in DataList abdul_owiusa General .NET 1 May 20th, 2005 09:01 AM
Datalist does not display data sanjeet ADO.NET 1 August 8th, 2003 11:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.