0

私のグリッドビューはこれに似ています:

12- CategoryA - other columns
13- CategoryA - other columns
14- CategoryA - other columns
15- CategoryA - other columns

16- CategoryB - other columns
17- CategoryB - other columns
18- CategoryB - other columns

私が欲しいのはそのようなものです:

CategoryA (colspan 2) 
12 - other columns 
13 - other columns 
14 - other columns 
15 - other columns 
Category B (colspan 2) 
16 - other columns
17 - other columns 
18 - other columns

データソースとしてバインドするデータテーブルを変更することでこれを行うことはできますか? それとももっと簡単な方法がありますか?

4

2 に答える 2

2

RowDataBoundイベントが必要になると思います。以前に表示されたカテゴリと表示されるカテゴリを追跡できます。

class MyClass
{
    private string CurrentCategory{ get; set; }

    // Load_Page with databinding the GridView{  }

    protected void mygridview_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if(e.Row.RowType == DataControlRowType.DataRow && 
          (e.Row.DataItem as DataRowView)["mycolumn"].ToString() != CurrentCategory))
        {
            GridViewRow tr = new GridViewRow(e.Row.RowIndex +1, e.Row.RowIndex + 1, 
                                   DataControlRowType.DataRow, e.Row.RowState);
            TableCell newTableCell = new TableCell();
            newTableCell.Text = (e.Row.DataItem as DataRowView)["mycolumn"].ToString();
            CurrentCategory = (e.Row.DataItem as DataRowView)["mycolumn"].ToString();
            tr.Cells.Add(newTableCell);

            ((Table)e.Row.Parent).Rows.Add(tr);
        }
    }
}

コードは現状のまま提供され、テストされていません。

于 2013-04-02T13:59:43.353 に答える
0

GridView コントロールは、グループ化をネイティブにサポートしていません。

于 2013-04-02T13:35:20.607 に答える