how do you add conditional statement to datagrid TemplateColumn

G

Giorgio

Hi,

Is it possible to add a condition to the value being displayed in a
datagrid template column? Based on the value in the container item I
would like to display one of 2 <asp:Lable> controls.

here is what essentially i'm trying to accomplish

<asp:TemplateColumn HeaderText="ChrgStaDesc" >
<ItemTemplate>
<% if Container.DataItem("detail") <> "" then %>
<asp:Label id= "lblDescription" runat= "server" Text= '<%#
Container.DataItem("detail") %>'></asp:Label>
<% else %>
<asp:Label id= "lblDescription" runat= "server" Text= '<%#
Container.DataItem("detail2") %>'></asp:Label>
<% end if %>
</ItemTemplate>
</asp:TemplateColumn>

thanks in advance!!
 
E

Eliyahu Goldin

Handle ItemDataBound event. You have full access to the item and to the
columns and can do whatever you want programmatically.

Eliyahu
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top