帮忙看看,这个样式怎么实现?(高分)

yanyl2001 2004-08-11 04:02:53
数据:
|---------|---------|--------|----------|----------|
| a | a1 | b1 | c1 | d1 |
|---------|---------|--------|----------|----------|
| a | a2 | b2 | c2 | d2 |
|---------|---------|--------|----------|----------|
| a | a3 | b2 | c3 | d3 |
|---------|---------|--------|----------|----------|
| b | a1 | b3 | c4 | d4 |
|---------|---------|--------|----------|----------|
| c | a1 | b4 | c5 | d4 |
|---------|---------|--------|----------|----------|
| c | a1 | b4 | c6 | d5 |
|---------|---------|--------|----------|----------|

1、要求可以按任意一列分组:(分组列有顺序,第一列)
|---------|---------|--------|----------|----------|
| | a1 | b1 | c1 | d1 |
| |---------|--------|----------|----------|
| a | a2 | b2 | c2 | d2 |
| |---------|--------|----------|----------|
| | a3 | b2 | c3 | d3 |
|---------|---------|--------|----------|----------|
| b | a1 | b3 | c4 | d4 |
|---------|---------|--------|----------|----------|
| | a1 | b4 | c5 | d4 |
| C |---------|--------|----------|----------|
| | a1 | b4 | c6 | d5 |
|---------|---------|--------|----------|----------|
***************************************************************************
(第一列,第二列)
|---------|---------|--------|----------|----------|
| | a1 | b1 | c1 | d1 |
| |---------|--------|----------|----------|
| a | a2 | b2 | c2 | d2 |
| |---------|--------|----------|----------|
| | a3 | b2 | c3 | d3 |
|---------|---------|--------|----------|----------|
| b | a1 | b3 | c4 | d4 |
|---------|---------|--------|----------|----------|
| | | b4 | c5 | d4 |
| C | a1 |--------|----------|----------|
| | | b4 | c6 | d5 |
|---------|---------|--------|----------|----------|
*****************************************************************************
2、 可以多行合并:(第四行)
|---------|---------|--------|----------|----------|
| | a1 | b1 | c1 | d1 |
| |---------|--------| |----------|
| a | a2 | b2 | c2 | d2 |
| |---------|--------| |----------|
| | a3 | b2 | c3 | d3 |
|---------|---------|--------|----------|----------|
| b | a1 | b3 | c4 | d4 |
|---------|---------|--------|----------|----------|
| | a1 | b4 | c5 | d4 |
| C |---------|--------| |----------|
| | a1 | b4 | c6 | d5 |
|---------|---------|--------|----------|----------|
**********************************************************************************
(第四行,第五行)
|---------|---------|--------|----------|----------|
| | a1 | b1 | c1 | d1 |
| |---------|--------| | |
| a | a2 | b2 | c2 | d2 |
| |---------|--------| | |
| | a3 | b2 | c3 | d3 |
|---------|---------|--------|----------|----------|
| b | a1 | b3 | c4 | d4 |
|---------|---------|--------|----------|----------|
| | a1 | b4 | c5 | d4 |
| C |---------|--------| | |
| | a1 | b4 | c6 | d5 |
|---------|---------|--------|----------|----------|
****************************************************************************************
3、增加小计行
|---------|---------|--------|----------|----------|
| | a1 | b1 | c1 | d1 |
| |---------|--------|----------|----------|
| a | a2 | b2 | c2 | d2 |
| |---------|--------|----------|----------|
| | a3 | b2 | c3 | d3 |
|---------|---------|--------|----------|----------|
| 小计 | a2+a3 | b2+b2 | c2+c3 | d2+d3 |
|---------|---------|--------|----------|----------|
| b | a1 | b3 | c4 | d4 |
|---------|---------|--------|----------|----------|
| 小计 | a1 | b3 | c4 | d4 |
|---------|---------|--------|----------|----------|
| | a1 | b4 | c5 | d4 |
| C |---------|--------|----------|----------|
| | a1 | b4 | c6 | d5 |
|---------|---------|--------|----------|----------|
| 小计 | a1+a1 | b4+b4 | c5+c6 | d4+d5 |
|---------|---------|--------|----------|----------|
| 合计 | …… | …… | …… | …… |
|---------|---------|--------|----------|----------|
我想大家应该明白我的意思了,看看要怎么实现,(分多的是)。
...全文
150 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanyl2001 2004-08-12
  • 打赏
  • 举报
回复
hareqiqi(蓝兔子.NET) :非常感谢你,你的代码很有用。如果还有关于合并多行内容在一行
中的方法,请告诉我。

在此也谢谢,上面几位大哥!
yungboy 2004-08-12
  • 打赏
  • 举报
回复
合并多列函数
Sub SpanGrid()
Dim i As Integer
Dim j As Integer
Dim intSpan As Integer
Dim strTemp As String
For i = 0 To datagrid1.Items.Count - 1
intSpan = 1

'得到第第一行、二十一列单元格中的内容。
strTemp = datagrid1.Items(i).Cells(21).Text

'循环判断。判断第二十一列中,和第一行相同的内容。相同做记号,intspan加一
For j = i + 1 To datagrid1.Items.Count - 1
If String.Compare(strTemp, datagrid1.Items(j).Cells(21).Text) = 0 Then
intSpan += 1

'利用datagrid的rowspan属性。(设置控件中单元格跨越的行数为intspan)
datagrid1.Items(i).Cells(21).RowSpan = intSpan

'把内容相同单元格隐藏
datagrid1.Items(j).Cells(21).Visible = False
Else
Exit For
End If
Next
i = j - 1
Next
End Sub

yanyl2001 2004-08-12
  • 打赏
  • 举报
回复
先谢谢了,还有合并多行和几个列同时分组。

我要在后台代码中实现公共程序段,通过传递参数,实现不同的样式。
hareqiqi 2004-08-11
  • 打赏
  • 举报
回复
不好意思,仔细看了一下你的小计,是统计组的。

这个功能最好还是在datatable里构造,然后绑定。
hareqiqi 2004-08-11
  • 打赏
  • 举报
回复
这些函数都是经过几个项目考验的,放心使用。

另外你提到的合计,可以在item_band里实现,也可以写成公共函数。
hareqiqi 2004-08-11
  • 打赏
  • 举报
回复
我可以给你我们自己写的公共函数,不过职能合并文字相同的行,和复制格式。你改改就可以用了。
这个代码里还有一些datagrid其他经常用到的函数,你也可以参考参考。

using System;
using System.Web.UI.WebControls;

namespace PublicFunction
{
/// <summary>
/// Common 的摘要说明。
/// </summary>
public class DataGridFunction
{
public DataGridFunction()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

/// <summary>
/// 判断DataGrid指定列中的DropDownList是否都填写了。
/// </summary>
/// <param name="p_dg">需要判断的DataGrid</param>
/// <param name="p_CloumnNO">列序号(0-N)</param>
/// <param name="ddlID">DropDownList控件ID</param>
/// <returns>全部都填写返回true,否则返回false</returns>
static public bool CheckColumnDropDownListFilled(DataGrid p_dg, int p_CloumnNO, String p_ddlID)
{
for (int i=0; i<p_dg.Items.Count; i++)
{
if ((p_dg.Items[i].Cells[p_CloumnNO].Visible) && (((DropDownList)p_dg.Items[i].Cells[p_CloumnNO].FindControl(p_ddlID)).SelectedIndex == 0))
return false;
}
return true;
}

/// <summary>
/// DataGrid合并相同内容的列单元格(空单元格不合并),不适用于“重要度”列。
/// </summary>
/// <param name="p_dg">需要合并的DataGrid</param>
/// <param name="p_ColumnNO">列序号(0-N)</param>
static public void SpanGrid(DataGrid p_dg, int p_ColumnNO)
{
int i,j;
int spanNum = 1;
string strCellText;
for (i=0; i<p_dg.Items.Count; i++)
{
strCellText = p_dg.Items[i].Cells[p_ColumnNO].Text.Trim();
if (strCellText != "" && strCellText != " ")
{
for (j=i+1; j<p_dg.Items.Count; j++)
{
if(strCellText == p_dg.Items[j].Cells[p_ColumnNO].Text.Trim())
{
spanNum++;
p_dg.Items[j].Cells[p_ColumnNO].Visible = false;
}
else
{
break;
}
}
p_dg.Items[i].Cells[p_ColumnNO].RowSpan = spanNum;
i = j - 1;
spanNum = 1;
}
}
}

/// <summary>
/// 根据某一列的格式合并另一列的单元格,适用于“重要度”列。
/// </summary>
/// <param name="p_dg">需要合并的DataGrid</param>
/// <param name="SourceColumnm">源格式列(0-N)</param>
/// <param name="ObjectColumn">目标列(0-N)</param>
static public void CopySpan(DataGrid p_dg, int SourceColumn, int ObjectColumn)
{
for (int i=0; i<p_dg.Items.Count; i++)
{
p_dg.Items[i].Cells[ObjectColumn].RowSpan = p_dg.Items[i].Cells[SourceColumn].RowSpan;
p_dg.Items[i].Cells[ObjectColumn].Visible = p_dg.Items[i].Cells[SourceColumn].Visible;
}
}

/// <summary>
/// 判断DataGrid中某个下拉框列优秀填写比例是否不超过30%
/// </summary>
/// <param name="p_dg">DataGrid</param>
/// <param name="p_ColumnNO">列序号</param>
/// <param name="p_ddlID">下拉框ID</param>
/// <returns>true-不超过,false-超过</returns>
static public bool Check30Per(DataGrid p_dg, int p_ColumnNO, String p_ddlID)
{
int Total = p_dg.Items.Count;
int Good = 0;
int MaxGood = 1;
for (int i=0; i<Total; i++)
{
if (((DropDownList)p_dg.Items[i].Cells[p_ColumnNO].FindControl(p_ddlID)).SelectedIndex == 1)
Good++;
}
if (Total > 4)
MaxGood = Convert.ToInt32((Double.Parse(Total.ToString()) * 30) / 100);
if (Good > MaxGood)
return false;
else
return true;
}

/// <summary>
/// 判断DataGrid中指定Type列和下拉框列的同类别中优秀比例是否不超过30%
/// </summary>
/// <param name="p_dg">DataGrid</param>
/// <param name="p_ColumnNO">下拉框列序号</param>
/// <param name="p_ddlID">下拉框ID</param>
/// <param name="p_TypeColumnNO">Type列序号</param>
/// <returns>true-不超过,false-超过</returns>
static public bool Check30Per(DataGrid p_dg, int p_ColumnNO, String p_ddlID, int p_TypeColumnNO)
{
String[] arrType = {"党群", "机关", "街道"};
//while ()
int Total = 0;
int Good = 0;
int MaxGood = 1;
for (int i=0; i<p_dg.Items.Count; i++)
{
Total++;
if (((DropDownList)p_dg.Items[i].Cells[p_ColumnNO].FindControl(p_ddlID)).SelectedIndex == 1)
Good++;
}
if (Total > 4)
MaxGood = Convert.ToInt32((Double.Parse(Total.ToString()) * 30) / 100);
return true;
}

/// <summary>
/// 根据完成情况百分数生成进度条html语句,当进度小于40%时,文字显示在右半部分,当进度大于等于40%时,文字显示在左半部分。
/// </summary>
/// <param name="completed">完成情况</param>
/// <returns>进度条html</returns>
static public String ShowProgress(String completed)
{
int progress;
String ProgressList = String.Empty;
if( (completed.Trim() == " ") || (completed.Trim() == String.Empty) || (completed.Trim() == "0"))
{
return String.Empty;
}
else
{
progress = System.Int32.Parse(completed);

int blank = 100 - progress;

String leftStr, rightStr;
if (progress < 40)
{
leftStr = String.Empty;
rightStr = "<font color=#7f7f7f>" + progress.ToString().Trim() + "%</font>";
}
else
{
leftStr = "<font color=#f7f7f7>" + progress.ToString().Trim() + "%</font>";
rightStr = String.Empty;
}
ProgressList +="<table width=100% height=16px border=0 cellpadding=0 cellspacing=0 class=label>";
ProgressList +="<tr><td align=center valign=center width="+progress.ToString()+"% bgcolor=#e02121>"+leftStr+"</td>"
+"<td align=center valign=center width="+blank.ToString()+"% bgcolor=#efefef>"+rightStr+"</td></tr></table>";
}
return ProgressList;
}

}
}
wxlada 2004-08-11
  • 打赏
  • 举报
回复
实现方法是把rowspan,colspan的值,计算出来, 也加到DataTable中去。然后用模板列绑定这个值。实现复杂的表格。
fangbuge 2004-08-11
  • 打赏
  • 举报
回复
分再高也不会
Jasonchen82 2004-08-11
  • 打赏
  • 举报
回复
可以使用其它Datagrid控件。。有下载。。
www.asp.net
eboywy 2004-08-11
  • 打赏
  • 举报
回复
UP
佣工7001 2004-08-11
  • 打赏
  • 举报
回复
呵呵,都是五星上将阿
acewang 2004-08-11
  • 打赏
  • 举报
回复
third: Summary Rows in DataGrid Controls
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndive/html/data01102002.asp
孟子E章 2004-08-11
  • 打赏
  • 举报
回复
参见

http://www.xmlasp.net/show.aspx?id=392&cid=12
孟子E章 2004-08-11
  • 打赏
  • 举报
回复
RowSpan
ColSpan方法
guguniaoufo 2004-08-11
  • 打赏
  • 举报
回复
我顶,我顶,我顶顶顶!
楼主,要是解决了问题。请共享!

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧