Solved

asp:repeater conditional statement

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

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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