Binding an ASP.NET GridView Control to a string array
Posted
by Michael Kniskern
on Stack Overflow
See other posts from Stack Overflow
or by Michael Kniskern
Published on 2009-06-03T16:26:07Z
Indexed on
2010/04/21
9:33 UTC
Read the original article
Hit count: 562
I am trying to bind an ASP.NET GridView
control to an string
array and I get the following item:
A field or property with the name 'Item' was not found on the selected data source.
What is correct value I should use for DataField property of the asp:BoundField column in my GridView control. Here is my source code:
ASPX page
<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>
Code Behind:
string[] MyArray = new string[1];
MyArray[0] = "My Value";
MyGridView.DataSource = MyArray;
MyGridView.DataBind();
UPDATE
I need to have the AutoGenerateColumns
attribute set to false
because I need to generate additional asp:CommandField
columns. I have updated my code sample to reflect this scenarion
© Stack Overflow or respective owner