问题描述
我有一个名单,其中,串>
,我使用一个数据源
为的GridView
。我不想自动生成的列(它给项目为头)。我怎么把为数据字段
如果我用得到的字符串的BoundField
?又名<%#的eval([whatgoeshere])%>
的标记
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] ) %>
in the markup?
推荐答案
您将不得不使用的TemplateField在这种情况下,而不是绑定列,如:
You will have to use TemplateField in that case and not BoundField like:
<asp:TemplateField HeaderText="My Header">
<ItemTemplate>
<%#Container.DataItem %>
</ItemTemplate>
</asp:TemplateField>
但要列标题的根本问题是项目,您可以设置列头,$ C $用的AutoGenerateColumns C-背着你所需的值。例如,
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";
这篇关于名单&LT;字符串&GT;作为GridView的数据源。做什么我在GV的绑定列置于数据字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!