Binding Generic List Array to GridView

后端 未结 3 1742
慢半拍i
慢半拍i 2021-01-28 07:53

Hi I have a List which returns an array of \"Question\". My question is how can I bind this to a grid view? When I try to call Question.Ordinal I get that it does not exist in

相关标签:
3条回答
  • 2021-01-28 08:34

    Just set it directly to Ordinal, as the first examples in the post you just linked to:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
       <asp:BoundField HeaderText="ID" DataField="CustId" />
       <asp:BoundField HeaderText="Name" DataField="Name" />
       <asp:BoundField HeaderText="City" DataField="City" />
    </Columns>
    </asp:GridView>
    

    Say:

    <asp:BoundField HeaderText="A Header" DataField="APropertyOfQuestion" />
    
    0 讨论(0)
  • 2021-01-28 08:41

    you must be define the property member of class, as a propery ie

    public string ProductName
    {
        get
        {
            return _productName;
        }
        set { }
    
    }
    

    Or VB

    public property ProductName() as string set ..

    get...

    end property

    important: Is Required defined get method

    0 讨论(0)
  • 2021-01-28 08:43

    Try using the following syntax:

    <%# ((MyObject)Container.DataItem).MyField %>
    
    0 讨论(0)
提交回复
热议问题