0
我有一个包含GridView的用户控件。我将一个IEnumerable数据源对象传递给用户控件实例。我如何使用ForEach循环遍历用户控制代码中的数据源以显示我想要从数据源获得的列?ASP.NET GridView用户控件问题
到目前为止,我在代码下面的代码在用户控件的背后:
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();
}
感谢您的回复。我想我需要一个代码示例,因为我不明白。 – Theomax
目前我不想让它变得通用。我想知道如何从数据源对象中指定在gridview中使用哪些列。 – Theomax
所以请编辑你的问题,显示IEnumerable中对象的属性。为什么是IEnumerable