在gridview绑定后显示(VS2005-C#-asp.ent)
gridview标题  姓名      物品     价格    说明
              王        电脑     100     不保修
              王        钢笔     10      派克
              王        11       12      22
              王        33       29      33
              李飞      手机     200     三星
              李飞      电脑     1000    华硕
              李飞      33       33       44  
              王健      34       二三     11
              王健      电脑     3000     联想
              王健      电视机   30000    三星
是人名对应多个物品。什么方法在gridview显示成;
              姓名      物品     价格    说明
              王        电脑     100     不保修
                        钢笔     10      派克
                        11       12      22
                        33       29      33
              李飞      手机     200     三星
                        电脑     1000    华硕
                        33       33       44  
              王健      34       二三     11
                        电脑     3000     联想
                        电视机   30000    三星
这个人的姓名显示一个  其它的物品正常显示
能显示成这种方式都可以
     

解决方案 »

  1.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (ViewState["shownames"] == null)
            {
                ArrayList shownames = new ArrayList();
                ViewState["shownames"] = shownames;
            }        if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ArrayList shownames = (ArrayList)ViewState["shownames"];
                for (int i = 0; i < shownames.Count; i++)
                {
                    if (shownames[i].ToString() == e.Row.Cells[0].Text.Trim())
                    {
                        e.Row.Cells[0].Text = "";
                        return;
                    }
                }
                shownames.Add(e.Row.Cells[0].Text.Trim());
                ViewState["shownames"] = shownames;
            }
        }
      

  2.   

    protected void GridView1_DataBound(object sender, System.EventArgs e) 

        TableCell oldTc = myGrid1.Rows(0).Cells(0); 
        for (int i = 1; i <= myGrid1.Rows.Count - 1; i++) { 
            TableCell tc = myGrid1.Rows(i).Cells(0); 
            if (oldTc.Text == tc.Text) { 
                tc.Visible = false; 
                if (oldTc.RowSpan == 0) { 
                    oldTc.RowSpan = 1; 
                } 
                oldTc.RowSpan += 1; 
                
                oldTc.VerticalAlign = VerticalAlign.Middle; 
            } 
            else { 
                oldTc = tc; 
            } 
        } 
    }
      

  3.   

    protected void GridView1_DataBound(object sender, System.EventArgs e) 

        TableCell oldTc = GridView1.Rows(0).Cells(0); 
        for (int i = 1; i <= GridView1.Rows.Count - 1; i++) { 
            TableCell tc = GridView1.Rows(i).Cells(0); 
            if (oldTc.Text == tc.Text) { 
                tc.Visible = false; 
                if (oldTc.RowSpan == 0) { 
                    oldTc.RowSpan = 1; 
                } 
                oldTc.RowSpan += 1; 
                
                oldTc.VerticalAlign = VerticalAlign.Middle; 
            } 
            else { 
                oldTc = tc; 
            } 
        } 
    }