Checking Evaluated grid value in ascx file

123 views Asked by At

I'm trying to modify text in an ASCX file based on the value chosen in a grid. This syntax doesn't work.

 <p>
 The letter should be <%#If(DataBinder.Eval(Container.DataItem, "Code") == "A" Then A Else B)%>
 </p>

This should render as "The letter should be A" or "The letter should be B". Can this be done dynamically? The grid is on the same ascx page.

1

There are 1 answers

2
Albert D. Kallal On

Well, if that markup is to be inside of a grid view?

Then you still have to template that column.

So, say this:

          <asp:TemplateField HeaderText="test column">
              <ItemTemplate>
                  <p>
                      <%# IIf(Eval("City") = "Edmonton", "E", Eval("City")) %>
                  </p>
              </ItemTemplate>
          </asp:TemplateField>

So, if the data (city column) = "Edmonton", then we show "E", else we show the value.

And that's not code - but has to be a legal single VB expression.

So, if() or iif() is a vb.net function - they are both the same - and there is no "then" or "else" when you use that function.