Solved

asp:repeater conditional statement

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looping through datagridview and dataset ? 6 24
Passing data between Forms 3 20
Finding the IIS version 5 22
How to filter by key press ? 6 25
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…
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.…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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