List作为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>

你可能感兴趣的:(GridView)