How to call a code-behind method from aspx page?

前端 未结 1 1106
北荒
北荒 2020-12-10 13:21

I\'ve an object that contains a field called DevList which is defined like this

public List DevList { get; set; }
相关标签:
1条回答
  • 2020-12-10 14:02

    Assuming this is how your class looks:

    public class MyItem
    {
        public List<string> DevList { get; set; }
    }
    

    And that

    ds = List<MyItem>();
    

    Do this:

    In your code-behind:

    protected string DisplayListOfDevelopers(object _devList)
    {
        //Cast your dev list into the correct object
    }
    

    In your markup:

    <asp:TemplateField HeaderText = "Developer(s)">
     <ItemTemplate>
       <asp:Label 
            ID="_lblDevList" 
            runat="server" 
            Text= '<%# DisplayListOfDevelopers(Eval("DevList")) %>'>
       </asp:Label>
     </ItemTemplate>
    </asp:TemplateField>
    

    Just be sure to make the function in your code-behind is protected or public.

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