我有一个通过代码生成列的网格视图,还有来自 aspx 的 ItemTemplate 字段,如何在不清除模板字段的情况下清除从代码生成的列?
我之前帖子中的代码
TemplateField templateField = new TemplateField();
TemplateField uid = new TemplateField();
uid.HeaderText = "userid";
uid.ItemTemplate = new AddItemTemplate(ListItemType.Item, "userid");
GridView1.Columns.Add(uid);
for (int i = 0; i < dt.Columns.Count; i++)
{
BoundField boundField = new BoundField();
if (dt.Columns[i].ColumnName.ToString() != "userid")
{
boundField.DataField = dt.Columns[i].ColumnName.ToString();
boundField.HeaderText = dt.Columns[i].ColumnName.ToString();
GridView1.Columns.Add(boundField);
}
}
aspx
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td>
<div id="div<%# Eval("userid") %>" >
<asp:GridView ID="GridView2" AllowSorting="true" >
<Columns>
--code--
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>