Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
600
WebDataGrid - Evaluating fields inside of a TemplateDataField
posted

I have a WebDataGrid which has a column I've defined as a TemplateDataField.

In that field, I want to display data conditionally depending on the values of Field1 and Field 2

Field1 always has data, so I display it as follows:

<ig:TemplateDataField Key="ContactPersons">
<ItemTemplate>
  <%# DataBinder.Eval(CType(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "Field1")%>
 </ItemTemplate>
</ig:TemplateDataField>

However, I first need to test the contents of Field2 to determine if I want to display it as well in that same column.

I'm wanting to use something similar to this:

<ig:TemplateDataField Key="ContactPersons">
 <ItemTemplate>
  <%# DataBinder.Eval(CType(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "Field1")%>
  <%
       Dim strField2 As String
       strField2 = DataBinder.Eval(CType(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "Field2")
       if strField2 <> "" then
             'Code for displaying Field2 here 
       end if
  %>
 </ItemTemplate>
</ig:TemplateDataField>

The strField2= line above does not work because that's the wrong syntax. 

My question is how do I retrieve data elements inside of an ItemTemplate so that I can evaluate them and add conditional logic?  How do I retrieve the value of Field2 so I can evaluate it?

strField2 = ????

Thanks,

John

Parents
No Data
Reply
  • 6748
    Verified Answer
    posted

    Hello John,

     

    You can create a protected function in your code-behind that will perform the checks that you would like:

    Protected Function ComputeField(ByRef field1 As Object, ByRef field2 As Object) As String

           

            If field2 <> "" Then

                'Code for displaying Field2 here

            End If

            Return strField2

        End Function

    And then you can call it inside the item template:

    <%# ComputeField(DataBinder.Eval(CType(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "Field1"), DataBinder.Eval(CType(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "Field2"))%>

     

    Hope this helps.

    Regards,

    Lyuba

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

Children
No Data