[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1026
  • Last Modified:

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

I have repeater control under it I have the following

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

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

How can I do it?
0
asp123
Asked:
asp123
  • 2
2 Solutions
 
nauman_ahmedCommented:
write the following code on Row_Created method:
C#
====
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");  
             }
      }
   }
}

VB.NET
========
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
Next

--Nauman.
0
 
nauman_ahmedCommented:
correction:

write the following code on Row_Created event.

--Nauman.
0
 
Swapnil PipariaArchitectCommented:
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 %>'/>
</td>

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

Regards,
NetSwap.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now