Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asp:repeater conditional statement

Posted on 2008-10-22
4
Medium Priority
?
656 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 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

885 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