有关DataGrid的数据显示问题 自己手工构造一个datatable,然后绑定到datagrid中。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一下信息也许对你有用演示:http://www.asp.net/ReportsStarterKit/SourceViewer/srcview.aspx?path=masterdetail.src&file=masterdetail&rows=5下载地址:http://www.asp.net/StarterKits/DownloadReports.aspx comy(泥娃):Those are "creating and databinding two different DataGrids on the same page". 動態添加行可行﹐也可以從寫SQL 來解決 假如日期字段為 ApplyDate table為 tabtestselect (convert(varchar(4),year(ApplyDate))+'年' +convert(varchar(2),Month(ApplyDate)) +'月') as ApplyDate,* from tabtest Bobwu(king) :你这里只是添加了个字段而已,如果是在数据库中添加个记录我想也可以。chyich() :我想可以这样:select语句按时间顺序排列,然后显示记录的时候比较前后时间的月份,如果不同了添加行,然后就显示月。如何动态添加行呢? 如要你真的要动态的添加行,也可以,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]); 个人认为最好的办法是在后台用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 哥哥们请进来看看。 此版本的 SQL Server 不支持用户实例登录标志。该连接将关闭。 为什么修改不成功!!! VS与SQL SERVER连接的奇怪错误 水晶报表10数据集问题~??? 扑捉SoapException的错误信息后,Message信息处理!! [提议]高手们都来用屏幕录像专家搞一些实例操作的视频教程,这样对我们这些菜鸟的学习有帮助。 简单代码,书上原码,不能运行! CSDN中的程序谁谁在维护和开发啊! 页面转发问题 PANEL的问题 Web.Config文件能动态修改吗?在线。。
演示:
http://www.asp.net/ReportsStarterKit/SourceViewer/srcview.aspx?path=masterdetail.src&file=masterdetail&rows=5
下载地址:
http://www.asp.net/StarterKits/DownloadReports.aspx
也可以從寫SQL 來解決
假如日期字段為 ApplyDate table為 tabtestselect (convert(varchar(4),year(ApplyDate))+'年' +convert(varchar(2),Month(ApplyDate)) +'月') as ApplyDate,* from tabtest
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]);
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