时间:2016-02-16 01:04 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【asp.net中GridView和DataGrid相同列合并实现代码】,下面是详细的讲解!
asp.net中GridView和DataGrid相同列合并实现代码
/// <summary>
/// Gridview列的合并(普通列,不包含模板列)
/// 注意:1.GridView在绑定的时候进行分组和排序,才能让相同的行放在一起
/// 2.方法应用的时机,应该在Gridview的DataBound事件中使用
/// </summary>
/// <param name="gv">需要合并的GridView对象</param>
/// <param name="columnIndex">所要合并列的索引</param>
public static void UnitCell(GridView gv, int columnIndex)
{
int i=0; //当前行数
string lastType=string.Empty; //当前判断是否合并行对应列的值
int lastCell=0; //判断最后一个相同值的行的索引
if (gv.Rows.Count > 0)
{
lastType=gv.Rows[0].Cells[columnIndex].Text.ToString();
gv.Rows[0].Cells[columnIndex].RowSpan=1;
lastCell=0;
}
for (i=1; i < gv.Rows.Count; i++)
{
if (gv.Rows[i].Cells[columnIndex].Text==lastType)
{
gv.Rows[i].Cells[columnIndex].Visible=false;
gv.Rows[lastCell].Cells[columnIndex].RowSpan++;
}
else
{
lastType=gv.Rows[i].Cells[columnIndex].Text.ToString();
lastCell=i;
gv.Rows[i].Cells[columnIndex].RowSpan=1;
}
}
}
/// <summary>
/// DataGrid列的合并(普通列,不包含模板列)
/// 注意:1.DataGrid在绑定的时候进行分组和排序,才能让相同的行放在一起
/// 2.方法应用的时机,应该在DataGrid的DataBound事件中使用
/// </summary>
/// <param name="dg">需要合并的DataGrid对象</param>
/// <param name="columnIndex">所要合并列的索引</param>
public static void UnitCell_T(DataGrid dg, int columnIndex)
{
int i=0; //当前行数
string lastType=string.Empty; //当前判断是否合并行对应列的值
int lastCell=0; //判断最后一个相同值的行的索引
if (dg.Items.Count> 0)
{
lastType=dg.Items[0].Cells[columnIndex].Text.ToString();
dg.Items[0].Cells[columnIndex].RowSpan=1;
lastCell=0;
}
for (i=1; i < dg.Items.Count; i++)
{
if (dg.Items[i].Cells[columnIndex].Text==lastType)
{
dg.Items[i].Cells[columnIndex].Visible=false;
dg.Items[lastCell].Cells[columnIndex].RowSpan++;
}
else
{
lastType=dg.Items[i].Cells[columnIndex].Text.ToString();
lastCell=i;
dg.Items[i].Cells[columnIndex].RowSpan=1;
}
}
}
关于asp.net中GridView和DataGrid相同列合并实现代码的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【ASP】ASP.NET中内嵌页面代码的一个问题-NET-内
- 【As】Asp.net中的页面乱码的问题-sp--pn-ne-et
- 【增加记录】asp.net中获取新增加记录的ID Access
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【Asp】Asp.net 页面调用javascript变量的值-net-
- 【ASP】ASP.NET 5升级后如何删除旧版本的DNX-NET5
- 【404页面】ASP.NET设置404页面返回302HTTP状态码
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
