Search code examples
c#dotnetnukerepeatersqldatasource

How do I refer to <%# Eval('column')%> in a .aspx scripting tag?


Please note that I am using a SQLDATASOURCE to perform a SELECT * FROM myTable. Here is a small piece of the item template of my repeater:

<li>Work Extension: <%# Eval("WK_PHONE_EXT")%></li>

Now, lets say that <%# Eval("WK_PHONE_EXT")%> is an empty string. How do I go about referencing <%# Eval("WK_PHONE_EXT")%> in a <script language="c#" runat="server"> tag. I know i can do it from the codebehind, by placing the value of the EVAL tag in an asp:label text property then finding it. Im just looking for a shorter way to say:

if(<%# Eval("WK_PHONE_EXT")%> == ""){
<%# Eval("WK_PHONE_EXT")%> == "N/A";
}

So I do not have to rebuild my simple DNN Module. Is something like this possible?


Solution

  • You could check inline

       <%#(String.IsNullOrEmpty(Eval("WK_PHONE_EXT").ToString()) ? "N/A" : Eval("WK_PHONE_EXT"))%>
    

    EDIT:

    For complex conditions, I'd prefer to write a public (or protected) method in the codebehind & handle them there

    In UI.. '<%# MyDataItem(Eval("item")) %>'

    public string MyDataItem(object value)
    {
      if (string.IsNullOrEmpty(value.ToString()))
      {
         return "N/A";
      }
    
      return myValue.ToString();
    }