Conditional statement to display asp:textbox or asp:label

M

maflatoun

Hi,

I have a datagrid and based on a condition I like to display either a
asp:textbox or asp:label. How would I do that? I have the following


<asp:TemplateColumn HeaderText="Qty">
<ItemTemplate>
<% if (DataBinder.Eval(Container.DataItem, "DynamicAttribute") = "No")
{%>


<asp:textbox id="tbxQtyNew" BackColor='<%#
SetTextBoxColor(DataBinder.Eval(Container.DataItem,
"DynamicAttribute")) %>' runat="server" text='1' />
<% } else { %>
<asp:Label id="lblQtyDisp" Text="1" runat="server"/>
<% } %>
</ItemTemplate>

</asp:TemplateColumn>


Which fails. Any idea?


Thanks
Maz.
 
M

Marina Levit [MVP]

You can set the Visible property on each control accordingly. Something
like:

<asp:TextBox id="myTB" runat="server" Visible='<%# someVar = "Y" %>' />

But you of course substitute whatever boolean condition you have to
determine whether or not that item should be visible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top