抑制重复行显示

本文介绍如何在GRID中处理一对多的数据关系,并通过代码示例展示了如何仅展示第一行的相关信息,包括调整行背景色及突出显示价格等关键字段。

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

很多时候一对多的关系中 只需要显示第一行

最近就遇到这样的情况

客户订单 客户订单行 有可能是分批出货。欠交数量是个总数

客户订单 行 数量 出货数量 出货日期 欠交数量

A 001500 100 2010=05-01 100

A 001500 200 2010=05-02 100

A 001500 100 2010=05-03100

----------------------------------------------------------------

A 001500 100 2010=05-01 100

A 001 200 2010=05-02

A 001 100 2010=05-03

如果在水晶报表中很容易实现,但如果在GRID中呢

其实很简单

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "if(this!=prevselitem){this.style.backgroundColor='#Efefef'}");// 鼠 停留 更改背景色
e.Row.Attributes.Add("onmouseout", "if(this!=prevselitem){this.style.backgroundColor='#ffffff'}");// 鼠 移 原背景色
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{


currdoc = e.Row.Cells[1].Text.Trim ();
currline = e.Row.Cells[2].Text.Trim ();

if (currdoc == lastdoc && currline == lastline)
{

e.Row.Cells[13].Text = "0";
e.Row.Cells[14].Text = "0";
}
string strprice = e.Row.Cells[13].Text;//取出来的单元格的文本带有RMB字符串,如:<font color=red>RMB</font>50.47
double price = double.Parse(strprice);
if (price > 0)
{
e.Row.Cells[13].Text = "<font color=red>" + e.Row.Cells[13].Text + "</font>";
e.Row.Cells[14].Text = "<font color=red>" + e.Row.Cells[14].Text + "</font>";
// e.Row.BackColor = System.Drawing.Color.Yellow;//使用预设颜色来设置行的背景色
//e.Row.ForeColor = System.Drawing.Color.FromName("#ff0000");//使用十六进制的颜色,设置前景色
}
else
{
e.Row.Cells[13].Text = "";
e.Row.Cells[14].Text = "";
}

}
lastdoc = currdoc;
lastline = currline;
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值