【发布时间】:2018-05-14 10:07:07
【问题描述】:
我有一个包含许多列的数据表,就像这样;
Name | Age | Foo | Bar | Etc..Joe | 30 | foo | bar | Etc..
我现在需要将此数据表分成两列,其中仅包含标题及其值,如下所示;
Header | ValueName | JoeAge | 30Foo | fooEtc... | etc..
这样 DataBinder 可以在绑定数据时轻松访问它。
如何做到这一点,我是否需要这样做?
编辑:包括示例代码
asp.net
<div class="itemDetail col-s">
<div class="itemDetailLabel">
<%# DataBinder.Eval(Container.DataItem, "Caption")%>
</div>
<div class="itemDetailValue">
<%# If(DataBinder.Eval(Container.DataItem, "UIValue") Is Nothing OrElse String.IsNullOrEmpty(DataBinder.Eval(Container.DataItem, "UIValue").ToString()), " ", DataBinder.Eval(Container.DataItem, "UIValue")) %>
</div>
</div>
vb.net
Dim oldDataTable As DataTable = DataSource ''Which is a datatable of a single row
Dim newDataTable As New DataTable
newDataTable.Columns.Add("Caption")
newDataTable.Columns.Add("UIValue")
''Change the single row into multiple rows
fooControl.DataSource = newDataTable
fooControl.DataBind()
EDIT2:所以对于像我一样还在学习的人来说,这叫做转置。感谢@gofal3 指出
【问题讨论】:
-
您应该将您当前的代码添加到问题中,以便我们可以帮助您解决问题
-
@ValerioSantinelli 示例代码示例有帮助吗?