Have you ever used IIF? Explain.

 Posted by Bhakti on 12/7/2009 | Category: VB.NET Interview questions | Views: 3690

Sometimes, you need to bind data using ternary functions from code file. With VB, you can achieve this thing using IIF function.

For an example, here in code below at the time of databinding I need to check value of “testString”. If the value is null/empty string it shows “NA” else the value.

<%#IIf(String.IsNullOrEmpty(DataBinder.Eval(Container.DataItem, "testString")), "NA", DataBinder.Eval(Container.DataItem, " testString "))%>

You can achieve the same result from code behind by placing appropriate code in itemdatabound method.(if applicable)

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response