【发布时间】:2011-11-20 08:19:27
【问题描述】:
我有一个包含 GridView 的用户控件。我将一个 IEnumerable 数据源对象传递给用户控件实例。如何在后面的用户控件代码中使用 ForEach 循环遍历数据源以显示数据源中我想要的列?
到目前为止,我在用户控件后面的代码中有如下代码:
public IEnumerable<object> DataSource { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
this.GridView1.DataSource = DataSource;
foreach (var item in DataSource)
{
//The line below gives an error - what's the correct way to do this?
this.GridView1.Columns.Add(new BoundColumn() {DataField = "What to put here", HeaderText = "What to put here"; }
}
this.GridView1.DataBind();
}
【问题讨论】:
标签: c# asp.net user-controls