设为首页   |  加入收藏夹 快速导航:  热门文章  |  最新文章  |  梦想博客  
当前位置:编程之家 -> 文章频道 ->asp.net 
站内搜索:  

DataGrid用法:合并内容相同的单元格

作者:生活碎片 来源:blog 整理日期:2007-09-28

**//// <summary>
        /// DataGrid中相同单元格的合并
        /// </summary>
        public void SpanGrid()
        ...{
            int i;
            int j;
            int intSpan;
            string strTemp;

            for (i = 0; i < DataGrid1.Items.Count;)
            ...{
                intSpan = 1;
               
                strTemp = DataGrid1.Items[i].Cells[0].Text;
               
                //循环判断,判断第一列中,和第一行相同的内容
                for (j = i + 1; j < DataGrid1.Items.Count; j ++)
                ...{
                    if (string.Compare(strTemp, DataGrid1.Items[j].Cells[1].Text) == 0)
                    ...{
                        intSpan += 1;

                        //利用datagrid的RowSpan属性
                        DataGrid1.Items[i].Cells[0].RowSpan = intSpan;

                        //把内容相同单元格隐藏
                        DataGrid1.Items[j].Cells[0].Visible = false;
                    }
                    else
                    ...{
                        break;
                    }                   
                }

                i = j -1;
            }
        }