一个Datagrid样式

本文介绍了一种使用C#实现的数据网格合并方法,通过比较相邻行的特定字段来减少重复显示,提高了数据展示效率。该方法适用于需要展示大量相似数据项的应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

private void BindGrid()
            {
                QueryOpen qo = new QueryOpen();
                ZDXK.BLL.Scholar bll=new ZDXK.BLL.Scholar();
                DataTable dt = bll.GetList(qo.GetSubjectID()).Tables[0];
                this.DataGrid1.DataSource = dt;
                this.DataGrid1.DataBind();

                int i;
                int j;
                int intspan;
                string temp;
                for(i=0;i<DataGrid1.Items.Count;i++)
                {
                    DataGridItem _item = DataGrid1.Items[i];
                    intspan = 1;
                    temp = DataGrid1.Items[i].Cells[0].Text;
                    for(j=i+1;j<DataGrid1.Items.Count;j++)
                    {
                        if(String.Compare(temp, DataGrid1.Items[j].Cells[0].Text)== 0)
                        {
                            intspan++;
                            DataGrid1.Items[i].Cells[0].RowSpan = intspan;
                            DataGrid1.Items[j].Cells[0].Visible = false;
                        }
                        else
                        {
                            break;
                        }
                    }
                    i=j-1;
                }
            }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值