自己手工构造一个datatable,然后绑定到datagrid中。

解决方案 »

  1.   

    一下信息也许对你有用
    演示:
    http://www.asp.net/ReportsStarterKit/SourceViewer/srcview.aspx?path=masterdetail.src&file=masterdetail&rows=5
    下载地址:
    http://www.asp.net/StarterKits/DownloadReports.aspx
      

  2.   

    comy(泥娃):Those are "creating and databinding two different DataGrids on the same page".
      

  3.   

    動態添加行可行﹐
    也可以從寫SQL 來解決 
    假如日期字段為 ApplyDate table為  tabtestselect (convert(varchar(4),year(ApplyDate))+'年' +convert(varchar(2),Month(ApplyDate)) +'月') as ApplyDate,* from tabtest
      

  4.   

    Bobwu(king) :你这里只是添加了个字段而已,如果是在数据库中添加个记录我想也可以。chyich() :我想可以这样:select语句按时间顺序排列,然后显示记录的时候比较前后时间的月份,如果不同了添加行,然后就显示月。如何动态添加行呢?
      

  5.   

    如要你真的要动态的添加行,也可以,datagrid在绑定数据以后,生成了一个htmltable控件,而htmltable控件其实就是html里的<table>,它由htmltablerow(<tr>)组成,而htmltablerow又由htmltablecell组成(<td>).然后你用htmltablerow的addat方法在htmltable中增加新的行(htmltablerow对象)。下面是datagrid增加多行表头的代码,你研究一下,对你有帮助:
    SqlDataReader sdr=scd.ExecuteReader();
    DataGrid1.DataSource=sdr;
    DataGrid1.DataBind();
    sdr.Close();
    //获得分类名
    string str_sel_type="select typename from ty_jj_type where typeno=" + str_type_code;
    SqlCommand scd1=new SqlCommand(str_sel_type,scn);
    string str_type_name=(string)scd1.ExecuteScalar();
    scn.Close();
    //加多行的表头
    Table t = (Table)DataGrid1.Controls[0];
    DataGridItem row = new DataGridItem(0, -1, ListItemType.Header);
    t.Rows.AddAt(0, row);
    TableCell tc3=new TableCell();
    tc3.Text="1";
    row.Cells.Add(tc3);
    TableCell tc=new TableCell();
    tc.ColumnSpan=8;
    tc.Text=str_type_name;
    row.Cells.Add(tc);
    DataGridItem row1 = new DataGridItem(0, -1, ListItemType.Header);
    t.Rows.AddAt(0, row1);
    TableCell tc4=new TableCell();
    tc4.Text="地区";
    row1.Cells.Add(tc4);
    TableCell tc1=new TableCell();
    tc1.ColumnSpan=4;
    tc1.Text=" 查处价格违法情况";
    row1.Cells.Add(tc1);
    TableCell tc2=new TableCell();
    tc2.Text="实施经济制裁情况";
    tc2.ColumnSpan=4;
    row1.Cells.Add(tc2);
    t.Rows[0].Cells[0].RowSpan=3;
    t.Rows[1].Cells.Remove(t.Rows[1].Cells[0]);
    t.Rows[2].Cells.Remove(t.Rows[2].Cells[0]);
      

  6.   

    个人认为最好的办法是在后台用ado.net构造datatable,不是很麻烦。你可以看看下面的几篇文章,对你也许有帮助:
    http://expert.csdn.net/Expert/topic/1548/1548020.xml?temp=.8161585http://expert.csdn.net/Expert/topic/1544/1544487.xml?temp=.6819574http://msdn.microsoft.com/library/en-us/dndive/html/data01102002.asp