protected void Button1_Click(object sender, EventArgs e)
{
System.Collections.ArrayList list = new System.Collections.ArrayList();
list.Add("abc");
list.Add("xyz");
list.Add("pqr");
list.Add("efg");
开发者_如何学JAVA GridView1.DataSource = list;
GridView1.DataBind();
}
Now when data is bound to the gridview the column name is by default "Items" but I want to change the header text of this column. How to do this..?
Since you are using auto generated columns, check the Fields collection. Access the first field (Fields[0]) and change the HeaderText to the new value.
Set the HeaderText property of the BoundField, like it's done here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.aspx
I was able to get the GridView
to bind properly and display a column heading of My Header by doing this:
.aspx
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:BoundField HeaderText="My Header" DataField="Value" />
</Columns>
</asp:GridView>
.aspx.cs
System.Collections.ArrayList list = new System.Collections.ArrayList();
list.Add(new ListItem("abc"));
list.Add(new ListItem("xyz"));
list.Add(new ListItem("pqr"));
list.Add(new ListItem("efg"));
GridView1.DataSource = list;
GridView1.DataBind();
精彩评论