Telerik RadGrid在编辑模式下会导致值异常吗?

时间:2016-07-27 19:53:16

标签: c# asp.net telerik

我当然希望有人能够帮助我,而我却有一丝理智:(

我有一个radgrid,数据绑定通过LINQ查询。它显示应该,我添加了一个工作正常的详细信息按钮。但当我点击编辑按钮时,我得到: “JavaScript运行时错误:Sys.WebForms.PageRequestManagerServerErrorException:选择超出范围 参数名称:值“

我对我所获得的价值观进行了深思熟虑,我没有看到问题,显而易见或其他问题。我的网格跟着(对不起,这有点乱):

 <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" 
        CellSpacing="0" GridLines="None" AllowPaging="True" 
       DataMember="id" 
        onneeddatasource="RadGrid1_NeedDataSource" 
            OnUpdateCommand="RadGrid1_UpdateCommand" PageSize="20" 
            onitemcommand="RadGrid1_ItemCommand" >
<MasterTableView DataKeyNames="status,charity,make,model,year,vin,date,id,salePrice,bid,note" 
            EditMode="EditForms" EnableViewState="True">

<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>

    <Columns>
    <telerik:GridButtonColumn CommandName="History" Text="History" UniqueName="detailBtn" HeaderText="History" HeaderButtonType="PushButton" AutoPostBackOnFilter="True">
                        </telerik:GridButtonColumn>
     <telerik:GridBoundColumn HeaderText="Charity" ItemStyle-Width="140px" FilterControlAltText="Filter column2 column" 
            UniqueName="column3" DataType="System.String" DataField="charity" ReadOnly="True">
<ItemStyle Width="140px"></ItemStyle>
        </telerik:GridBoundColumn>
         <telerik:GridBoundColumn HeaderText="VIN" ItemStyle-Width="140px" FilterControlAltText="Filter column6 column" 
            UniqueName="column7" DataType="System.String" DataField="vin" >
<ItemStyle Width="140px"></ItemStyle>
             </telerik:GridBoundColumn>
      <telerik:GridBoundColumn HeaderText="Year" ItemStyle-Width="140px" FilterControlAltText="Filter column2 column" 
            UniqueName="column2" DataType="System.Int32" DataField="year">
<ItemStyle Width="140px"></ItemStyle>
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn HeaderText="Make" ItemStyle-Width="140px" FilterControlAltText="Filter column column" 
            UniqueName="column" DataType="System.String" DataField="make">
<ItemStyle Width="140px"></ItemStyle>
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn HeaderText="Model" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" 
            UniqueName="column1" DataType="System.String" DataField="model">
<ItemStyle Width="140px"></ItemStyle>
            </telerik:GridBoundColumn>            
             <telerik:GridBoundColumn HeaderText="Last Update" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" 
            UniqueName="column5" DataType="System.DateTime" DataField="date" ReadOnly="True">
<ItemStyle Width="140px"></ItemStyle>
        </telerik:GridBoundColumn>
         <telerik:GridBoundColumn HeaderText="Min. Bid" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" 
            UniqueName="column8" DataType="System.Decimal" DataField="bid" DataFormatString="{0:C}" >
<ItemStyle Width="140px"></ItemStyle>
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn  HeaderText="Sale Price" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" 
            UniqueName="column6" DataType="System.Decimal" DataField="salePrice" DataFormatString="{0:C}" Display="False">
<ItemStyle Width="140px"></ItemStyle>
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn  HeaderText="Notes" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" 
            UniqueName="unsoldNotesColumn" DataType="System.String" DataField="note" Display="True">
<ItemStyle Width="140px"></ItemStyle>
        </telerik:GridBoundColumn> 
      <telerik:GridTemplateColumn HeaderText="Latest Status" ItemStyle-Width="240px">


                        <ItemTemplate>

                            <%#DataBinder.Eval(Container.DataItem, "Status")%>

                        </ItemTemplate>


                        <EditItemTemplate>

                            <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="updateComboBox" DataTextField="Status" 

                                DataValueField="ID" DataSourceID="LinqDataSource1" SelectedValue='<%#Bind("ID") %>' AutoPostBack="True"
                                >

                            </telerik:RadComboBox>                          

                        </EditItemTemplate>


<ItemStyle Width="240px"></ItemStyle>


                    </telerik:GridTemplateColumn>

                    <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn"

                        HeaderText="Edit" HeaderStyle-Width="100px" UpdateText="Update">

<HeaderStyle Width="100px"></HeaderStyle>

                    </telerik:GridEditCommandColumn>



    </Columns>

<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>

<FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>

我的代码隐藏,如果与此有关,则为:

 private void LoadUnsoldVehicleGrid()
        {


            CAAData2DataContext db = new CAAData2DataContext();


            var ud = db.Updates

             .Where(c => c.Sold.Equals(false))
             .GroupBy(c => c.Vehicle)
            .Select(x => x.OrderByDescending(y => y.TimeStamp).First()).ToList();

            var unSoldVehicles = (from u in ud
                                  join v in db.Vehicles on
                                      u.Vehicle equals v.ID
                                  join c in db.Customers on
                                  v.Charity equals c.ID
                                  select new  
                                {
                                    status = u.Status,
                                    make = v.Make,
                                    model = v.Model,
                                    Year = v.Year,
                                    vin = v.VIN_,
                                    charity = c.Name,
                                    date = u.TimeStamp,
                                    id = u.Vehicle,
                                    salePrice = v.SalePrice,
                                    bid = v.MinimumBid,
                                    note=u.Note
                                }).OrderBy(z=>z.charity).ToList();

            RadGrid1.DataSource = unSoldVehicles;



        }

令人非常沮丧的是......这是有效的。我必须在不经意间改变一些事情,当我意识到这一切都是......呃

我会非常感激任何见解!

1 个答案:

答案 0 :(得分:1)

j

最有可能的问题来自上面的代码块。您可以做的是在<telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="updateComboBox" DataTextField="Status" DataValueField="ID" DataSourceID="LinqDataSource1" SelectedValue='<%#Bind("ID") %>' AutoPostBack="True"> </telerik:RadComboBox> 控件上调用SelectedValue方法后在代码中设置DataBind。希望它有所帮助。

RadComboBox