Solved

asp:repeater conditional statement

Posted on 2008-10-22
4
649 Views
Last Modified: 2013-11-07
First let me say that I am a super newbie so if you provide assistance, please give it in a detailed format so I know how to implement it.  :-)

I have a Repeater that I finally got to work, but I want to "hide" a table row (TR) if the value of a field (show_notes) is equal to "no".

Below is the code I am using. I read a bunch of tips but I cannot get it to work. Some of them had code behind solutions but I was not sure how to implement them.

I also included some of the code behind code if needed.

Thanks.

Mitch
<asp:Repeater ID="rptrExample" runat="server"> 
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table>
     <tr>
          <td>Notes:</td>
          <td>
               <%#DataBinder.Eval(Container, "DataItem.notes")%>
          </td>
     </tr>
and so on ...
 
Code Behind:
 
sql = String.Format("SELECT * FROM [vw_get_customers] WHERE [custid] = {0}", theCriteria)
conn = New SqlConnection(ConfigurationManager.AppSettings("connection_string"))
conn.Open()
cmdCourse = New SqlCommand(sql, conn)
 
rptrExample.DataSource = cmdCourse.ExecuteReader()
rptrExample.DataBind()

Open in new window

0
Comment
Question by:Mitchel-T
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:JimDestruct
ID: 22777102
<%#IIf(DataBinder.Eval(Container.DataItem, "show_notes") = "no", DataBinder.Eval(Container.DataItem, "DataItem.notes"), "")%>
0
 

Author Comment

by:Mitchel-T
ID: 22777239
JimDestruct:

Regretfully this is not working.

When I replace:

<%#DataBinder.Eval(Container, "DataItem.notes")%>

With:

<%#IIf(DataBinder.Eval(Container, "show_notes") = "yes", DataBinder.Eval(Container, "DataItem.notes"), "")%>

None of the information in my repeater is displayed.

Also...I want to make the entire <tr>...</tr> not visible if "show_notes" = no
0
 
LVL 1

Accepted Solution

by:
JimDestruct earned 125 total points
ID: 22777327
ok, I take it that the column your wanting to display is "Notes" so, that being the case try the following:

<asp:Repeater ID="rptrExample" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table>

<%#IIf(DataBinder.Eval(Container.DataItem, "show_notes") = "yes", "<tr><td>Notes:</td><td>" & DataBinder.Eval(Container.DataItem, "notes") & "</td></tr>", "")%>


fingers crossed!! :D

0
 

Author Comment

by:Mitchel-T
ID: 22777893
JimDestruct:

It WORKED perfectly!

Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

630 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