Solved

Programatically control Datalist Item Template

Posted on 2003-11-10
2
1,151 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help on C# Linq query on object 6 62
SlingPlayer alternatives 1 44
Not seen Link button 5 37
C# Gridview 1 27
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now