Conditional Showing of Information in Repeater Control (ASP.NET)

Posted on 2007-08-02
Last Modified: 2008-01-09
I have repeater control under it I have the following

                    <td><asp:Label ID="iComment" runat="server" Text='<%#Eval("Comment") %>' /></td>
                <tr >
                    <td style="font-style:italic"><asp:Label ID="iInstruction" runat="server" Text='<%#"Instruction: " + Eval("Instruction") %>' /></td>

I want to include the Instruction in italic only if it exists in the next line.

How can I do it?
Question by:asp123
    LVL 25

    Accepted Solution

    write the following code on Row_Created method:
    foreach(Control c in e.Item.Controls)
      if (c.GetType() == typeof(Label))
          Label lbl = (Label)c;
          if (lbl.ID.IndexOf("iInstruction") == 0)
                  if (Eval("Instruction").ToString() != "")
                           lbl.Font.Italic = true;
                           lbl.Text = Eval("Instruction");  

    For Each c As Control In e.Item.Controls
        If (c.GetType = GetType(Label)) Then
            Dim lbl As Label = CType(c,Label)
            If (lbl.ID.IndexOf("iInstruction") = 0) Then
                If (Eval("Instruction").ToString <> "") Then
                    lbl.Font.Italic = true
                    lbl.Text = Eval("Instruction")
                End If
            End If
        End If

    LVL 25

    Expert Comment


    write the following code on Row_Created event.

    LVL 16

    Assisted Solution

    by:Swapnil Piparia
    Hi asp123,
    you can do following,

    <td ><asp:Label ID="iInstruction" runat="server" Text='<%#"Instruction: " + Eval("Instruction") %>' Font-Italic ='<%# Eval("Instruction").ToString().Length > 40 ? True : False %>'/>

    here in place of length condition you can try your own condition or say fix line length.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now