nikdonovanau
asked on
ASP.NET simple if statement
Hi Experts.
I have a simple page that displays a data repeater.
My question is.
If there are no records returned how do i NOT display the repeater at all.
I thought maybe
<%
dim strCount
strCount = Get_Students1.RecordCount
if strCount < 1 then %>
<asp:Repeater DataSource="<%# Get_Students1.DefaultView %>" ID="Repeat1" runat="server">
<HeaderTemplate>
<table width="500" style="font: 8pt verdana" border="1">
<tr style="background-color:DF A894">
<th>
First
</th>
<th>
Last
</th>
<th>
DOB
</th>
<th>
M/F
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:FF ECD8">
<td>
<%# Get_Students1.FieldValue(" Surname", Container) %>
</td>
<td>
<%# Get_Students1.FieldValue(" GivenNames ", Container) %>
</td>
<td>
<%# trim(left(Get_Students1.Fi eldValue(" DateOfBirt h", Container),10)) %>
</td>
<td>
<%# Get_Students1.FieldValue(" Gender", Container) %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater><% end if %>
But I dont know the correct syntax to use
Please Help
Cheers
Beginner on ASP.NET
I have a simple page that displays a data repeater.
My question is.
If there are no records returned how do i NOT display the repeater at all.
I thought maybe
<%
dim strCount
strCount = Get_Students1.RecordCount
if strCount < 1 then %>
<asp:Repeater DataSource="<%# Get_Students1.DefaultView %>" ID="Repeat1" runat="server">
<HeaderTemplate>
<table width="500" style="font: 8pt verdana" border="1">
<tr style="background-color:DF
<th>
First
</th>
<th>
Last
</th>
<th>
DOB
</th>
<th>
M/F
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:FF
<td>
<%# Get_Students1.FieldValue("
</td>
<td>
<%# Get_Students1.FieldValue("
</td>
<td>
<%# trim(left(Get_Students1.Fi
</td>
<td>
<%# Get_Students1.FieldValue("
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater><% end if %>
But I dont know the correct syntax to use
Please Help
Cheers
Beginner on ASP.NET
ASKER
Thanks for that. Using the gridview can you still have control of the data?
I used repeater because I can munaully code the href links in the output if I need to.
I just found a workaround after reading your post. If i put the if statement inside the headertemplate like this
<HeaderTemplate>
<table width="500" style="font: 8pt verdana" border="1">
<% if Get_Students1.RecordCount > 0 then %><tr style="background-color:DF A894">
<th>
First
</th>
<th>
Last
</th>
<th>
DOB
</th>
<th>
M/F
</th>
</tr><% end if %>
</HeaderTemplate>
it works a treat.
But im assuming its not best practice to do it this way, yes/no?
Thanks again
I used repeater because I can munaully code the href links in the output if I need to.
I just found a workaround after reading your post. If i put the if statement inside the headertemplate like this
<HeaderTemplate>
<table width="500" style="font: 8pt verdana" border="1">
<% if Get_Students1.RecordCount > 0 then %><tr style="background-color:DF
<th>
First
</th>
<th>
Last
</th>
<th>
DOB
</th>
<th>
M/F
</th>
</tr><% end if %>
</HeaderTemplate>
it works a treat.
But im assuming its not best practice to do it this way, yes/no?
Thanks again
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ahh, I see. Thanks for your help. That makes sense.
Im slowly getting there.
Im slowly getting there.
<asp:GridView ID="GridView1" runat="server" EmptyDataText="nothing to see here">
nothing to see here - would be what the users saw if no data was returned