如何在列表视图中使用列表视图?我有一个项目列表,每个项目都有一个标签列表。
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("title")%>'></asp:Label>
<asp:ListView ID="ListView2" runat="server"
DataSource='<%#getTagDatasource((string)Eval("tags"))%>'>
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#Container.DataItem%>'></asp:Label></div>
</ItemTemplate>
</asp:ListView>
</ItemTemplate>
</asp:ListView>第二个listview的数据源是一个字符串数组,其中包含标签列中包含的标签数组(是用',‘分隔的单个字符串。我在getTagDatasource方法中使用表中的tags.split(',‘)形成的数据源字符串数组。
现在这不起作用了,因为它显示无法将'System.DBNull‘类型的对象强制转换为'System.String’类型。
有没有人能解决我的问题?
发布于 2011-01-25 03:08:45
在getTagDatasource方法中,在开头执行此操作:
public string[] getTagDatasource(object data)
{
if (!(data is string) || data == null)
return new string[] { };
return data.ToString().Split(",");
}首先检查无效数据。
HTH。
https://stackoverflow.com/questions/4785775
复制相似问题