Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.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数据源时出现异常_C#_.net_Listview - Fatal编程技术网

C#-尝试设置ListView数据源时出现异常

C#-尝试设置ListView数据源时出现异常,c#,.net,listview,C#,.net,Listview,我正在尝试使用LINQ查询设置ListView的数据源。当我在调试时查看ListView时,它确实按照预期设置了数据源,但是它不会在我的web表单上更新 我的Web表单列表视图: <asp:ListView ID="SampleDisplayControl" runat="server"> <LayoutTemplate> <audio src='<%

我正在尝试使用LINQ查询设置ListView的数据源。当我在调试时查看ListView时,它确实按照预期设置了数据源,但是它不会在我的web表单上更新

我的Web表单列表视图:

<asp:ListView ID="SampleDisplayControl" runat="server">
                        <LayoutTemplate>   
                            <audio src='<%# Eval("Url") %>' controls="" preload="none"></audio>                                
                        </LayoutTemplate>
                        <ItemTemplate>
                            <asp:Literal ID="label" Text='<%# Eval("Title") %>' runat="server"/>                                     
                        </ItemTemplate>
                    </asp:ListView>
正在引发的异常:

引发异常:中的“System.InvalidOperationException” System.Web.Extensions.dll

还将退出一组线程:

线程已退出,代码为0(0x0)


我不确定为什么这不起作用,因为在一个类似的项目中,我以前使用过这段代码,没有任何问题。

问题是我的html。我需要在布局模板中设置占位符,并在中设置和标签。一个愚蠢的错误,因为我误解了如何组织布局

<LayoutTemplate>
                            <audio id="itemPlaceholder" controls="" preload="none" runat="server"></audio>                               
                            <asp:Literal ID="labelPlaceholder" runat="server"/>                                        
                        </LayoutTemplate>
                        <ItemTemplate>                           
                            <audio src='<%# Eval("Url") %>' controls="" preload="none"></audio>
                            <asp:Literal ID="label" Text='<%# Eval("Name") %>' runat="server"/>                                                                
                        </ItemTemplate> 


您在哪里看到异常?在您的代码中,它是经过处理的,因此不应该中断页面加载。表单没有更新可能是因为“通过使用适当的事件提供排序、更新、删除和分页功能”。我建议您在中间使用LINQDATABORCE,而不是直接分配LINQ压缩结果。我发现它是什么,我需要设置占位符。
<LayoutTemplate>
                            <audio id="itemPlaceholder" controls="" preload="none" runat="server"></audio>                               
                            <asp:Literal ID="labelPlaceholder" runat="server"/>                                        
                        </LayoutTemplate>
                        <ItemTemplate>                           
                            <audio src='<%# Eval("Url") %>' controls="" preload="none"></audio>
                            <asp:Literal ID="label" Text='<%# Eval("Name") %>' runat="server"/>                                                                
                        </ItemTemplate>