Accessing public static class files from .ASPX file using Eval(“”) from gridView

流过昼夜 提交于 2019-12-11 09:10:07

问题


Hi I am new to this system, please be gentle with me. The problem I am now having is the inability to call the class file from ASPX through Eval. The class file is located in "~/classes" folder. Please provide me with methods and ways to evade this error or even solve it thank you!! ^^

Programming language : C#
Problem found in : .ASPX gridView
Problem also found in : EstateDBManager class file
Error Message : DataBinding: 'DWAD_Project.classes.Volunteer' does not contain a property with the name 'EstateDBManager'.
Codes for partial gridView below :

    <asp:TemplateField HeaderText="Estate Name" SortExpression="EstateId">
      <EditItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("EstateDBManager.findEstate({0}).Name") %>'></asp:TextBox>
      </EditItemTemplate>
      <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("EstateDBManager.findEstate({0}).Name") %>'></asp:Label>
      </ItemTemplate>
    </asp:TemplateField>

Codes for partial EstateDBManager Class file below:

    namespace DWAD_Project.classes
    {
      public static class EstateDBManager
      {
        public static Estate findEstate(int ID)
        {
           // processes ...
        }
      }
    }

Thanks for replies and helps!! ^^






Answer to the problem:
GridView :

      <asp:TemplateField HeaderText="Estate Name" SortExpression="EstateId">
      <EditItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# DWAD_Project.classes.EstateDBManager.findEstate(Eval("EstateId")).Name %>'></asp:TextBox>
      </EditItemTemplate>
      <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# DWAD_Project.classes.EstateDBManager.findEstate(Eval("EstateId")).Name %>'></asp:Label>
      </ItemTemplate>
    </asp:TemplateField>

Class file :

    namespace DWAD_Project.classes
    {
      public static class EstateDBManager
      {
        public static Estate findEstate(int ID)
        {
           // processes ...
        }
      }
    }

回答1:


Eval is for properties of the data source. If you need just code don't use Eval

'<%# EstateDBManager.findEstate(Eval("EstateId")).Name %>'

You just have to convert the Eval result to the right type since it is object (e.g. (int)Eval("EstateId"))



来源:https://stackoverflow.com/questions/11492140/accessing-public-static-class-files-from-aspx-file-using-eval-from-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!