How to use Eval() with a column name that contains a dot(.)?

前端 未结 4 850
长情又很酷
长情又很酷 2021-01-05 05:20

In my SQL Server table there is a column slno. (yes, it contains a dot) that is working fine in SQL Server. However, <%#Eval(\"slno.\")%> is

相关标签:
4条回答
  • 2021-01-05 05:33

    I Used DataBinder.GetPropertyValue() as it follows:

    DataBinder.GetPropertyValue(Container.DataItem, "Name of my Fields with(Parentheses)") 
    

    and Worked like a Charm on a ASP.NET VB Project.

    0 讨论(0)
  • 2021-01-05 05:41

    You can use SELECT AS in your SELECT SQL statement.

    SELECT Tabl1.slno. AS slno_no_dot from Table1
    

    than

    <ItemTemplate> <%#Eval("slno_no_dot") %> </ItemTemplate>
    
    0 讨论(0)
  • 2021-01-05 05:46

    use

    <%# ((DataRowView)Container.DataItem)["slno."] %>
    

    Alternatively use

    <%# DataBinder.Eval (Container.DataItem, "slno.") %>
    

    For MSDN reference see http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx

    EDIT - Another option:

    <%# DataBinder.GetPropertyValue(Container.DataItem, "slno.") %>
    

    EDIT 2 - as per comments:

    AFAIK Eval handles the string as an expression which it evaluates using some rules - these rules have special handling for the dot...

    GetPropertyValue OTOH does not apply those rules (which means it is NOT a full replacement for Eval AFAIK) thus having the ability to handle cases where the dot handling of Eval leads to problems (like in this case).

    0 讨论(0)
  • 2021-01-05 05:52

    Do not use DataBinder.eval(); eval() can not read field after dot(.).

    Instead, use DataBinder.GetPropertyValue()

    0 讨论(0)
提交回复
热议问题