List<string> as GridView Datasource. What do I put for DataField in the GV's BoundField?
I have a List<string> that I'm using as a DataSource for a GridView. I don't want to auto generate the columns (it gives "Item" as the header). What do I put for the DataField to get the string if I'm using a BoundField? aka <%# Eval( [whatgoeshere] ) 开发者_StackOverflow中文版%> in the markup?
You will have to use TemplateField in that case and not BoundField like:
<asp:TemplateField HeaderText="My Header">
<ItemTemplate>
<%#Container.DataItem %>
</ItemTemplate>
</asp:TemplateField>
But to your root problem of column header being "Item" you can set your Column Header to your desired value in code-behind with AutoGenerateColumns. e.g.
GridView1.DataSource = list;
GridView1.DataBind();
GridView1.HeaderRow.Cells[0].Text = "My Custom Header";
You just need:
<%# GetDataItem().ToString() %>
See the MSDN documentation for more information.
You should be able to use
<%# Container.DataItem %>
to bind the string items to your GridView.
加载中,请稍侯......
精彩评论