如何从代码中填充asp:GridView?

时间:2012-10-18 15:02:15

标签: asp.net gridview binding

  

可能重复:
  How to populate asp:GridView from code?

我的代码中有一个填充了字符串数组的List<string[]> items列表。在ASPX页面上,我添加了一个新的网格视图控件:

<asp:GridView ID="ProductList" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ProductID" EnableViewState="False">
  <Columns>
    <asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />
    <asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />
    <asp:BoundField DataField="SupplierName" HeaderText="Supplier" ReadOnly="True" SortExpression="SupplierName" />
    <asp:BoundField DataField="UnitPrice" DataFormatString="{0:C}" HeaderText="Price" HtmlEncode="False" SortExpression="UnitPrice" />
    <asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" />
  </Columns>
</asp:GridView>

我知道我应该以类似于此的方式为网格视图指定DataSourceID属性:

<asp:GridView ... `DataSourceID="ObjectDataSource1" ... > 
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetProducts" TypeName="ProductsBLL">
</asp:ObjectDataSource>

但是,我不知道OldValuesParameterFormatStringSelectMethodTypeName属性代表什么。另外,我没有要绑定的数据库,我只有名为items的字符串数组列表。你能帮我填充网格视图吗?根本没有必要通过绑定来完成。

0 个答案:

没有答案