Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programatically control Datalist Item Template

Posted on 2003-11-10
2
Medium Priority
?
1,174 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 500 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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