I have a List that I am binding to a GridView, therefore my GridView will have only one column of these string values. I want to have a proper header-text for this column. Please help me. See what I have attempted to do:
<asp:GridView ID="GridView1" runat="server" Width="95%">
<Columns>
<asp:BoundField HeaderText="My List" />
</Columns>
</asp:GridView>
And in code behind:
List<string> myList = new List<string>();
:
:
// code to populate myList
:
:
GridView1.DataSource = myList;
GridView1.DataBind();
When I run this code, I get two columns in the GridView. First column having header-text as “My List” and having blank rows, whereas the second column having header-text as “Item” and having rows with myList values. I want to have only one column in my GridView having header-text as “My List” and rows with the values of the myList object.
Thanks
GridView1.DataSource = myList.ToArray();would do?