Solved

add IF condition to html

Posted on 2006-11-10
7
502 Views
Last Modified: 2010-05-18
Hi,


Im using VS2005 with VB.

I have the following line in my page:
<asp:DropDownList SelectedValue='<%#Eval("Status") %>' DataSourceID="odsStatusList" ID="ddlStatus" runat="server" DataTextField="Value" DataValueField="Key" /></td>

which creates a drop down list and binds the selected value.  What I want to do is:

if #Eval("Status") = "Draft" then

    <asp:DropDownList SelectedValue='<%#Eval("Status") %>' DataSourceID="odsStatusList" ID="ddlStatus" runat="server"       DataTextField="Value" DataValueField="Key" /></td>

else

   response.write("Status")

end if

but I dont know how to use the bound item (Status) within code in the page.

Thanks in advance!
0
Comment
Question by:jondow
  • 4
  • 2
7 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 17915818
use TemplateColumn.

See if this will work

<asp:TemplateColumn>
  <ItemTemplate>

<%# if Eval("Status") = "Draft" then%>

    <asp:DropDownList SelectedValue='<%#Eval("Status") %>' DataSourceID="odsStatusList" ID="ddlStatus" runat="server"       DataTextField="Value" DataValueField="Key" /></td>

<%# else%>

   <asp:Label id="lblStatus runat="server" Text="Status" />
<%# end if%>


</ ItemTemplate>
</asp:TemplateColumn>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17915844
also try

<asp:TemplateColumn>
  <ItemTemplate>

    <asp:DropDownList SelectedValue='<%#Eval("Status") %>' DataSourceID="odsStatusList" ID="ddlStatus" runat="server"       DataTextField="Value" DataValueField="Key" Visible='<%# iif(Eval("Status") = "Draft", True, False)%>' />

   <asp:Label id="lblStatus runat="server" Text="Status" Visible='<%# iif(Eval("Status") <> "Draft", True, False)%>' />
</ ItemTemplate>
</asp:TemplateColumn>
0
 
LVL 2

Author Comment

by:jondow
ID: 17915943
Hi,

its saying templatecolumn is not a known element - i guess because its not part of a gridview?

Anyway I'm off for the weekend now so I'll check back in next week.  Thanks.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 35

Expert Comment

by:YZlat
ID: 17915976
are you using Framework 1.1 or 2.0?
0
 
LVL 35

Accepted Solution

by:
YZlat earned 100 total points
ID: 17915978
then just try

<asp:DropDownList SelectedValue='<%#Eval("Status") %>' DataSourceID="odsStatusList" ID="ddlStatus" runat="server"       DataTextField="Value" DataValueField="Key" Visible='<%# iif(Eval("Status") = "Draft", True, False)%>' />

   <asp:Label id="lblStatus runat="server" Text="Status" Visible='<%# iif(Eval("Status") <> "Draft", True, False)%>' />
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17916816
>>I'm using VS2005 with VB.
The equivalent for TemplateColumn (1.1 DataGrid) with the GridView (2.0) is TemplateField.

Bob
0
 
LVL 2

Author Comment

by:jondow
ID: 17928791
Thanks Guys
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

856 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