Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Listview问题中的Listview_C#_Asp.net_Listview - Fatal编程技术网

C# Listview问题中的Listview

C# Listview问题中的Listview,c#,asp.net,listview,C#,Asp.net,Listview,如何在listview中使用listview? 我有一个项目列表,每个项目都有一个标签列表 <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"> <LayoutTemplate> <ul> <asp:PlaceHolder ID="itemPlaceholder" runat="server" />

如何在listview中使用listview? 我有一个项目列表,每个项目都有一个标签列表

<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的数据源是一个字符串数组,其中包含tags列中包含的标记数组(是一个用“,”分隔的单个字符串。我在getTagDatasource方法中形成的数据源字符串数组在表中带有tags.split(“,”)

现在这不起作用了,因为它说无法将“System.DBNull”类型的对象强制转换为“System.String”类型


有人能解决我的问题吗?

在getTagDatasource方法中,从一开始就执行以下操作:

public string[] getTagDatasource(object data)
{
    if (!(data is string) || data == null)
       return new string[] { };

    return data.ToString().Split(",");
}
首先检查无效数据