datagrid if thens

  • Thread starter Thread starter Trevor Hartman
  • Start date Start date
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
 
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
 
Back
Top