Solved

Programatically control Datalist Item Template

Posted on 2003-11-10
2
1,163 Views
Last Modified: 2008-02-01
Hello All -

 I am using a datalist to display XX rows as mini tables on a details page.

 I have another field being sent as part of the result set, (one that is not going to be displayed)

 Container.DataItem("Flagged")

I would like to be able to use this value in a comparisson test and if it evaluates to the specified value then change the background color of the current table being displayed.

For instance.

 My details query yields 3 rows in the result set.

 TotalGenerated : Subject : Message : Flagged

    10            15              23         0
   203            1           4          0
   100            32          23         1

 When displaying the results using the template below I would like to be able to do the following. ( I realize the code below would never work at all .. )

 If FLAGGED = 1 THEN
      Change the background color of the current Datalist Table to RED (or whatever)

 END IF


 Is this possible?

 If possible please try to make any examples in VB ( thanks in advance )

 

---------------------------------------------------------------------------------------
DATALIST ITEM TEMPLATE


 <asp:datalist id="dlStatDetails" Runat="server" RepeatDirection="Vertical" RepeatColumns="4">
                        <ItemTemplate>
                                          
                        
                        
                              <TABLE cellSpacing="1" cellPadding="1" width="100" border="1">
                                    <TR>
                                          <TD>Total Generated</TD>                                          <TD>
                                                <asp:label id="txtTotalGenerated" runat="server">
                                                      <%# Container.DataItem("TotalGenerated")%>
                                                </asp:label></TD>
                                    </TR>
                                    
                                                                        <TR>
                                          <TD>Subject</TD>
                                          <TD>
                                                <asp:Label id="txtSubject" runat="server">
                                                      <%# Container.DataItem("subject")%>
                                                </asp:Label></TD>
                                    </TR>
                                    <TR>
                                          <TD colspan="2">Message
                                                <asp:TextBox id="txtMessage" runat="server" Height="137px" Width="198px" TextMode="MultiLine" Text='<%# Container.DataItem("message") %>'>
                                                </asp:TextBox></TD>
                                    </TR>
                              </TABLE>
                        </ItemTemplate>
                  </asp:datalist>
0
Comment
Question by:drakum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 125 total points
ID: 9719655
Use ItemDataBound event of the DataList ...

    Private Sub MyDataList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles MyDataList.ItemDataBound
        If (e.Item.DataItem("FLAGGED") = 1) Then
            e.Item.BackColor = Color.Red
        End If
    End Sub
0
 

Author Comment

by:drakum
ID: 9724516
Thanks for your help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question