0

我有一个 GridView 。

它的数据源是data table我以编程方式创建它.cs以适应我想要展示的内容。现在我想在这个 gridview 中添加更多列作为包含文本框的模板字段。(作为我的数据表的一部分)。如何做到这一点。如果有样本或示例,这将是很棒的。

4

3 回答 3

1

Following tutorial will help you. This is on ASP.net 2.0 but there will not be a much different on latest versions.

http://msdn.microsoft.com/en-us/library/bb288032.aspx

Added Few other resources based on new comment

  1. http://www.highoncoding.com/Articles/29_Creating_Datagrid_columns_programmatically.aspx
  2. http://www.codeproject.com/KB/aspnet/create_template_columns.aspx?df=100&forumid=281019&exp=0&select=1726624
于 2011-07-30T13:37:38.757 回答
1

TemplateField bfield = new TemplateField();

bfield.HeaderTemplate = new GridViewTemplate(ListItemType.Header, col.ColumnName);

bfield.ItemTemplate = new GridViewTemplate(ListItemType.Item, col.ColumnName);

GrdView1.Columns.Add(bfield);

于 2011-07-30T14:30:01.030 回答
0
 <asp:TemplateField HeaderText="MyTextField">
            <ItemTemplate>
                <asp:TextBox runat="server" id="txtField">
            </ItemTemplate>
        </asp:TemplateField>

More details here: http://msdn.microsoft.com/en-us/library/aa479353.aspx

However, I think you're looking to do more than just this - but I can't be certain....

于 2011-07-30T13:37:29.287 回答