Solved

asp:repeater conditional statement

Posted on 2008-10-22
4
620 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
  • 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

21 Experts available now in Live!

Get 1:1 Help Now