在GridView中实现datalist 39;s RepeatColumns需要帮助
本文关键字:RepeatColumns 帮助 GridView 实现 datalist | 更新日期: 2023-09-27 17:52:47
默认情况下,在GridView
控件中没有RepeatColumns
属性来让我们向行中添加额外的单元格,就像在DataList
中那样。
我可以使用DataList
,但它没有我真正需要的寻呼机支持。所以我正在寻找方法来添加这样一个功能的GridView
。所以现在我想到了:
protected void GvwCollection_DataBound(object sender, EventArgs e)
{
for (int i = 0; i <= GvwCollection.Rows.Count; i++)
{
int x = 0;
int y = 0;
x = i % 4;
if (i != 0 && x != 0)
{
try
{
GvwCollection.Rows[y].Cells.Add(GvwCollection.Rows[i].Cells[0]);
}
catch { }
}
else { y = i; }
}
}
但它并没有像预期的那样工作。
最后,我需要得到这样的东西(一行4个单元格):
1 | 2 | 3 | 4
5 | 6 | 7 | 8
9 | 10 | 11 | 12
为什么不使用ListView -它可以根据您的要求平铺。看这个和这个
顺便说一句,你也可以在不使用DataPager控件的情况下使用DataList进行分页——参见
try this
protected void dgEmp_DataBound(object sender, EventArgs e)
{
int y = 0;
for (int i = 0; i < dgEmp.Rows.Count; i++)
{
if (i%4 ==0 && i!=0)
{
y++;
}
dgEmp.Rows[y].Cells.Add(dgEmp.Rows[i].Cells[0]);
}
}
使用Table服务器控件并以编程方式构建所有行/列。这将是最简单的方法,因为这样你就可以完全控制UI。gridview并不是用来做这个的
HTH .