本文介绍了在一个已排序的asp:GridView中进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在一个排序的asp:GridView中进行分组,如下图所示:
有人可以给我一个关于如何进行的暗示吗?是否有可能以某种方式在RowBound上进行分组?
解决方案
您可以使用以下算法来完成您的工作:
/ ****************************** **********
*分组算法
*BjörnKarpenstein
* http://www.capri-soft.de/blog
*** ************************************* /
// Nach dieser Spalte soll gruppiert werden
int k = 1;
//Füralle Zeilen(VON UNTEN NACH OBEN)
for(int i = GridView1.Rows.Count - 1; i> 0; i--)
{
GridViewRow row = GridView1.Rows [i];
GridViewRow previousRow = GridView1.Rows [i - 1]; ((row.Cells [k])的
//Füralle Spalten
(int j = 0; j {
。 Text == previousRow.Cells [k] .Text)&&(row.Cells [j] .Text == previousRow.Cells [j] .Text))
{
if(previousRow。单元格[j] .RowSpan == 0)
{
if(row.Cells [j] .RowSpan == 0)
{
previousRow.Cells [j] .RowSpan + = 2;
}
else
{
previousRow.Cells [j] .RowSpan = row.Cells [j] .RowSpan + 1;
}
row.Cells [j] .Visible = false;
}
}
}
}
I need a grouping in a sorted asp:Gridview like the following picture shows:
Can someone give me a hint about how to proceed? Is it possible to group on RowBound somehow?
解决方案
You can use the following algorithm to do your work:
/****************************************
* Grouping Algorithmus
* by Björn Karpenstein
* http://www.capri-soft.de/blog
****************************************/
// Nach dieser Spalte soll gruppiert werden
int k = 1;
// Für alle Zeilen (VON UNTEN NACH OBEN)
for (int i = GridView1.Rows.Count - 1; i > 0; i--)
{
GridViewRow row = GridView1.Rows[i];
GridViewRow previousRow = GridView1.Rows[i - 1];
// Für alle Spalten
for (int j = 0; j < row.Cells.Count; j++)
{
if ((row.Cells[k].Text == previousRow.Cells[k].Text) && (row.Cells[j].Text == previousRow.Cells[j].Text))
{
if (previousRow.Cells[j].RowSpan == 0)
{
if (row.Cells[j].RowSpan == 0)
{
previousRow.Cells[j].RowSpan += 2;
}
else
{
previousRow.Cells[j].RowSpan = row.Cells[j].RowSpan + 1;
}
row.Cells[j].Visible = false;
}
}
}
}
这篇关于在一个已排序的asp:GridView中进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!