datagrid if thens

T

Trevor Hartman

hi,
I want to display certain data in my edititemtemplate in the datagrid based
on the value of a column. How do I do an if then inside the datagrid AND
test the value of the current column. i only know how to refer to columsn
with the <%# DataBinder.Eval(Container.DataItem, "column") %>, and i can't
include an if then in the <%# %> block. any suggestions?
thanks
-trevor
 
S

Severin

Inside as datagrid control you can use the 'IIf([expression], True, False)'
function...

Any function calls in either the 'TruePart or Falsepart' will be called
regardless of the value of [expression]

I use this to toggle the 'visible' attribute in <asp:image /> controls in a
datagrid or datalist like so....

<asp:image id="imgLogo" imageUrl='<%# Container.DataItem("picpath") %>'
visible='<%# IIf(Container.DataItem("picpath") Is DbNull.Value, "False",
"True") %>' />

This IIf() function toggles the image visible to 'False' if "picpath" is
DbNull.Value, else it displays if there is a value in "picpath"

Severin
 

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