Solved

Programatically control Datalist Item Template

Posted on 2003-11-10
2
1,143 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
Comment Utility
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
Comment Utility
Thanks for your help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Whats wrong with this query 21 39
DataGridview Currency Formating? 22 38
Why is "packages element is not declared"? 2 37
Showdialog 8 20
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

16 Experts available now in Live!

Get 1:1 Help Now