C# 如何基于条件绑定网格视图中的数据

C# 如何基于条件绑定网格视图中的数据,c#,asp.net,gridview,C#,Asp.net,Gridview,我有空闲时间 ActualMachineId BlockScheduleVersionId ActualStartDate ActivityId BlockScheduleActivityId BLOCKNO UT13-PM-4 UT2-BSV-14 13/08/2014 UT13-ACT-11 UT2-BSA-2 2284 UT13-PM-4 UT2-BSV-6 08/06/2014 UT13-ACT-11 UT2-BSA-3 6396 UT1

我有空闲时间

ActualMachineId BlockScheduleVersionId  ActualStartDate ActivityId  BlockScheduleActivityId BLOCKNO 

UT13-PM-4   UT2-BSV-14  13/08/2014  UT13-ACT-11 UT2-BSA-2   2284    
UT13-PM-4   UT2-BSV-6   08/06/2014  UT13-ACT-11 UT2-BSA-3   6396    
UT13-PM-5   UT2-BSV-5   12/08/2014  UT13-ACT-11 UT2-BSA-4   1239    
UT13-PM-5   UT2-BSV-7   12/08/2014  UT13-ACT-11 UT2-BSA-5   2277    
UT13-PM-4   UT2-BSV-8   08/06/2014  UT13-ACT-11 UT2-BSA-6   1239    
UT13-PM-3   UT2-BSV-9   21/08/2014  UT13-ACT-11 UT2-BSA-8   2283    
如果我绑定数据,我也会得到所有重复的记录,但我不想这样,我需要像fallows一样的网格视图。在上述设置中,如果剩余的所有记录都相同,那么块号将通过分隔cama(如fallows)而在单行中

ActualMachineId BlockScheduleVersionId  ActualStartDate ActivityId  BlockScheduleActivityId BLOCKNO MachineName ActivityName
UT13-PM-4   UT2-BSV-14  13/08/2014  UT13-ACT-11 UT2-BSA-2   2284,6396       
UT13-PM-5   UT2-BSV-5   12/08/2014  UT13-ACT-11 UT2-BSA-4   1239,2277       
UT13-PM-4   UT2-BSV-8   08/06/2014  UT13-ACT-11 UT2-BSA-6   1239    
UT13-PM-3   UT2-BSV-9   21/08/2014  UT13-ACT-11 UT2-BSA-8   2283    
请帮助我提供建议。是否可以根据数据集创建动态数据表。如果可以,如何完成

这是我在检查之前声明的3个隐藏标签的值时尝试的方法

 if (e.Row.RowType == DataControlRowType.DataRow)
        {
            bool flag = false;
            string strBlockNos = lblBlockNos.Text;
            Label lblActualMachineId = (Label)e.Row.FindControl("lblActualMachineId");
            Label lblActivityId = (Label)e.Row.FindControl("lblActivityId");
            Label lblActualStartDate = (Label)e.Row.FindControl("lblActualStartDate");
            Label lblBlocks = (Label)e.Row.FindControl("lblBlocks");
            if (lblActualMachineId.Text == lblMachineId.Text)
            {

                if (lblActivityId.Text == lblActivityhidden.Text)
                {

                    if (lblActualStartDate.Text == lblStartDate.Text)
                    {

                        strBlockNos += lblBlocks.Text + ",";
                    }
                    else
                    {
                        lblMachineId.Text = lblActualMachineId.Text;
                        lblActivityhidden.Text = lblActivityId.Text;
                        lblStartDate.Text = lblActualStartDate.Text;
                        flag = true;
                    }
                }
                else
                {
                    lblMachineId.Text = lblActualMachineId.Text;
                    lblActivityhidden.Text = lblActivityId.Text;
                    lblStartDate.Text = lblActualStartDate.Text;
                    flag = true;
                }
            }
            else
            {
                lblMachineId.Text = lblActualMachineId.Text;
                lblActivityhidden.Text = lblActivityId.Text;
                lblStartDate.Text = lblActualStartDate.Text;

                flag = true;
            }
            if (flag == false)
            {
                e.Row.Visible = false;
            }
            else
            {
                //Here I need to update the previous row
            }
        }

提前感谢。

使用行数据绑定。因为我无法更新上一行的记录。请在您的问题中发表您的尝试。您能检查一下吗?如果我遗漏了什么,我的建议是创建新的datatable或model类,对数据进行分组并创建预期的结果。然后用数据绑定网格。我现在懒得为您键入答案,但以下是您可以做到的方法。使用Linq group by按块号分组,使用string.join将多个重复块号连接到一个逗号分隔的值中,然后将结果列表绑定到gridview。