关于对DataTable的操作

z22708387 2012-05-24 04:07:29


已有DataTable dt 绑定列表
DataRow dr = dt.NewRow(); //创建新的行
dr["aa"] = "合计";
dr["bb"] = Userdt.Compute("sum(bb)", "true").ToString();
dr["cc"] = Userdt.Compute("sum(cc)", "true").ToString();
dr["dd"] = Userdt.Compute("sum(dd)", "true").ToString();
dr["ee"] = Userdt.Compute("sum(ee)", "true").ToString();
dr["ff"] = Userdt.Compute("sum(ff)", "true").ToString();
dr["gg"] = Userdt.Compute("sum(gg)", "true").ToString();
dr["hh"] = Userdt.Compute("sum(hh)", "true").ToString();
dt.Rows.Add(dr);
dt.AcceptChanges();

这样是把加入的新行 放到DataTable的最后一行

有没有办法将 新加的一行放到第一行去呢?
...全文
183 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lugyedo 2012-05-24
  • 打赏
  • 举报
回复
dt.Rows.InsertAt(dr, 0);可以将数据添加到第一行

你说的格式是html的table,不是C#的DataTable,不是一回事儿
gxl19911228 2012-05-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
dt.Rows.InsertAt(dr, 0);//添加到开头
[/Quote]

++
dalmeeme 2012-05-24
  • 打赏
  • 举报
回复
dt.Rows.InsertAt(dr, 0);//添加到开头
xdq025 2012-05-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

引用 1 楼 的回复:

dt.Rows.InsertAt


另外 我的列头是两行。
格式为
<tr>
<th rowspan="2">
出价情况
</th>
<th rowspan="2">
……
[/Quote]

DataColumn dc=DataTable.Columns.Add();
dc.ColumnName="x";
z22708387 2012-05-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

dt.Rows.InsertAt
[/Quote]

另外 我的列头是两行。
格式为
<tr>
<th rowspan="2">
出价情况
</th>
<th rowspan="2">
排名
</th>
<th rowspan="2">
供应商ID
</th>
<th rowspan="2">
综合得分
</th>
<th colspan="2">
价格
</th>
<th colspan="2">
质量
</th>
<th colspan="2">
服务
</th>
<th colspan="2">
应变
</th>
</tr>
<tr>
<th>
权重
</th>
<th>
得分
</th>
<th>
权重
</th>
<th>
得分
</th>
<th>
权重
</th>
<th>
得分
</th>
<th>
权重
</th>
<th>
得分
</th>
</tr>

在添加的时候能够设置格式吗?
bdmh 2012-05-24
  • 打赏
  • 举报
回复
dt.Rows.InsertAt

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧