Solved

Programatically control Datalist Item Template

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

14 Experts available now in Live!

Get 1:1 Help Now