开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜