lundi, septembre 28, 2009

Conditional display in gridview

In a gridview, the cell is visible upon the value of an other column "Files" which returns True or False. Just use the Visible attribute of the control.



<asp:TemplateField HeaderText="" SortExpression="files">
<ItemTemplate>
<a href='<%# "corrections.aspx?id=/" + Eval("auto_id") %>'
visible='<%# DataBinder.Eval(Container.DataItem,"Files")%>' runat="server">

<img src="Images/icons/document_attachment.png" alt="Fichiers attachés" border="0" />
</a>
</ItemTemplate>
</asp:TemplateField>

Quite in the same maneer, show an image with a link only if the value in DB is not null or empty:

<asp:TemplateField HeaderText="Comment" SortExpression="description">
<ItemTemplate>
<img src="Images/icons/about.png" alt='<%# Bind("description") %>'
ID="aboutImg" runat="server" visible='<%# !String.IsNullOrEmpty(DataBinder.Eval(Container.DataItem,"description").ToString()) %>'/>
</ItemTemplate>
</asp:TemplateField>

Commentaires: Enregistrer un commentaire

Abonnement Publier les commentaires [Atom]





<< Accueil

This page is powered by Blogger. Isn't yours?

Abonnement Articles [Atom]