我正在尝试将 ASP.NET 的 GridView
控件绑定到一个 string
数组上,但是我得到了以下提示信息:
在所选数据源中找不到名称为“Item”的字段或属性。
在我的 GridView 控件中,asp:BoundField
列的 DataField 属性应该使用哪个正确的值?下面是我的源代码:
ASPX 页面
<asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Item" />
<asp:CommandField ButtonType="Link" ShowSelectButton="true" SelectText="Click Me!" />
</Columns>
</asp:GridView>
后台代码:
string[] MyArray = new string[1];
MyArray[0] = "My Value";
MyGridView.DataSource = MyArray;
MyGridView.DataBind();
更新
我需要将AutoGenerateColumns
属性设置为false
,因为我需要生成额外的 asp:CommandField
列。我已经更新了我的代码示例以反映这种情况。