List<string>作为GridView数据源时,绑定模板列的例子

I know this is an old post but I was looking for how to do the same, and this was a top result on google, so here is the simple answer for others.

just use Container.DataItem

Code
.cs 

List
<string> attributes = new List<string>();

narf.DataSource 
= attributes;
narf.DataBind();


.aspx

 
<asp:gridview ID="narf" runat="server">
            
<Columns>
            
<asp:TemplateField>
                
<ItemTemplate>
                    
<asp:TextBox ID="nasdc" runat="server" Text=<%# Container.DataItem %>></asp:TextBox>
                
</ItemTemplate>
            
</asp:TemplateField>
            
</Columns>
</asp:gridview>

 

原文讨论:How to bind a GridView to a List<string>

posted @ 2009-03-23 12:22  stu_acer  阅读(2550)  评论(1编辑  收藏  举报