如何在不使用 LINQ toEntity 的情况下将 gridview 中的数据转置到新的 gridview 中?
我是 LINQ 新手,希望能从任何知道如何使用 linq toEntity 转置网格中数据的人那里得到一些帮助?任何帮助将不胜感激。 提前致谢。
从...
ID Date Amount
1 2/1/2012 100
2 2/2/2012 200
3 2/3/2010 300
到...
ID 1 2 3
Date 2/1/2012 2/2/2012 2/3/2012
Amount 100 200 300
等等...
我得到了这个脚本并尝试将其用于我的目的,但我无法让它工作。现在我收到此错误消息 “'DBModel.Table1' 不包含 'Columns' 的定义,并且找不到接受类型为 'DBModel.Table1' 的第一个参数的扩展方法 'Columns'(您是否缺少 using 指令或程序集引用?) 以及行“'DBModel.Table1' 不包含 'Rows' 的定义”的相同错误消息 --请耐心等待,我来自数据库和 SQL 世界,所以所有帮助都会很棒。
private Table1 GetTransposedTable(Table1 fc)
{
Table1 newTable = new Table1();
newTable.Columns.Add(new DataColumn("0", typeof(string)));
for (int i = 0; i < fc.Columns.Count; i++)
{
DataRow newRow = newTable.NewRow();
newRow[0] = Convert.ToInt32(Session["Table1_ID"].ToString());
for (int j = 1; j <= fc.Rows.Count; j++)
{
if (newTable.Columns.Count < fc.Rows.Count + 1)
newTable.Columns.Add(new DataColumn(j.ToString(), typeof(string)));
newRow[j] = fc.Rows[j - 1][i];
}
newTable.Rows.Add(newRow);
}
return newTable;
}
I'm new to LINQ and was hoping to get some help from anyone that know how to transpose the data in a grid using linq to entities? Any help would be much appreciated.
Thanks in advance.
from...
ID Date Amount
1 2/1/2012 100
2 2/2/2012 200
3 2/3/2010 300
to...
ID 1 2 3
Date 2/1/2012 2/2/2012 2/3/2012
Amount 100 200 300
etc...
I got this script and trying to use it for my purposes but I can't get it to work. Now I get this error message
"'DBModel.Table1' does not contain a definition for 'Columns' and no extension method 'Columns' accepting a first argument of type 'DBModel.Table1' could be found (are you missing a using directive or an assembly reference?) and the same error message for rows "'DBModel.Table1' does not contain a definition for 'Rows'"
--Bear with me Im coming from databases and sql world, so all help would be wonderful.
private Table1 GetTransposedTable(Table1 fc)
{
Table1 newTable = new Table1();
newTable.Columns.Add(new DataColumn("0", typeof(string)));
for (int i = 0; i < fc.Columns.Count; i++)
{
DataRow newRow = newTable.NewRow();
newRow[0] = Convert.ToInt32(Session["Table1_ID"].ToString());
for (int j = 1; j <= fc.Rows.Count; j++)
{
if (newTable.Columns.Count < fc.Rows.Count + 1)
newTable.Columns.Add(new DataColumn(j.ToString(), typeof(string)));
newRow[j] = fc.Rows[j - 1][i];
}
newTable.Rows.Add(newRow);
}
return newTable;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用可模板化的控件,例如 ListView,而不是在可能的情况下转换数据。我想部分取决于您与 DataGrid 绑定了多少功能,但我认为其中大部分功能无论如何都会被格式的更改所破坏。
有关使用 ListView 的信息可以在此处找到:http://msdn.microsoft.com /en-us/library/bb398790.aspx。
I would suggest using a templatable control, like ListView, rather than transforming the data if its possible. I guess part of it depends on how much functionality you have tied to the DataGrid, but I would think most of that would be wrecked by the change in format anyway.
Information on using a ListView can be found here: http://msdn.microsoft.com/en-us/library/bb398790.aspx.