【问题标题】:Why does this Telerik Radgrid work some of the time为什么这个 Telerik Radgrid 有时会工作
【发布时间】:2016-03-23 14:23:49
【问题描述】:

我有一个不寻常的情况,我似乎无法解决。我有一个 Telerik RadGrid 设置来使用 .ascx Web 用户控件来编辑记录和添加新记录。该表单有 1 个 ASP.net DropdownList,当我编辑记录时可以正常工作。但是,当我尝试添加记录时,应用程序崩溃并显示以下错误消息:

'DropDownList1' 有一个无效的 SelectedValue,因为它不存在于项目列表中。 参数名称:value 说明:当前web请求执行过程中发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.ArgumentOutOfRangeException:“DropDownList1”有一个无效的 SelectedValue,因为它不存在于项目列表中。 参数名称:值

这是用于在 .ascx 页面上构建下拉菜单的代码。

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="EntityDataSource1" 
                    DataTextField="StatusDescription" DataValueField="StatusDescription" 
                    SelectedValue='<%# DataBinder.Eval(Container, "DataItem.Status") %>'>
                    <asp:ListItem Selected="True" Text="Select" Value="">
                        </asp:ListItem>
                </asp:DropDownList>

下拉列表的数据源使用 EntityDataSource,代码如下所示:

<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=TipsFileEntities1" DefaultContainerName="TipsFileEntities1" EntitySetName="Status"
                    Select="it.[StatusDescription], it.[StatusCode]" AutoPage="true" OrderBy="it.[StatusDescription]">
                </asp:EntityDataSource>

任何人都可以解释为什么表单会在没有错误的情况下呈现编辑而不是添加记录吗?以及有关如何修复它的任何建议。我已尝试清理和重建解决方案,但没有帮助。

谢谢 佩里

【问题讨论】:

    标签: c# asp.net telerik telerik-grid


    【解决方案1】:

    我能够找到解决此问题的方法。我在 DropDownList 中缺少一个设置。修正后的代码如下:

    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="EntityDataSource1" 
                        DataTextField="StatusDescription" DataValueField="StatusDescription" AppendDataBoundItems ="true" 
                        SelectedValue='<%# DataBinder.Eval(Container, "DataItem.Status") %>'>
                        <asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem>
                    </asp:DropDownList>
    

    我遗漏了 AppendDataBoundItems="true"。

    代码现在可用于添加和编辑记录

    【讨论】:

      猜你喜欢
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-04
      相关资源
      最近更新 更多