【问题标题】:Dropdown box Index issue下拉框索引问题
【发布时间】:2010-10-16 20:06:37
【问题描述】:

我有一个包含所有国家/地区的下拉框(ddlCountry),如果我选择美国,它将显示网格 显示与美国相关的税务信息。如果我编辑信息 在网格中,如果我们在下拉框中将国家美国更改为英国 在 ddlCountry(不是网格编辑窗口中的下拉框,没问题)它显示错误,如

指定的参数超出了有效值的范围。 参数名称:ItemHierarchicalIndex 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.ArgumentOutOfRangeException:指定的参数超出了有效值的范围。 参数名称:ItemHierarchicalIndex

来源错误:

第 86 行:} 第 87 行: 第 88 行:如果(rgStateTax.EditItems.Count > 0) 第 89 行:{ 第 90 行:foreach( rgStateTax.Items 中的 GridDataItem 项)

源文件:c:\Projects\ACS\sample.Acs.Administration\UserControls\TaxManager.ascx.cs 行:88

堆栈跟踪:

[ArgumentOutOfRangeException:指定的参数超出了有效值的范围。 参数名称:ItemHierarchicalIndex] Telerik.WebControls.GridItemCollection.get_Item(字符串分级索引)+323 Telerik.WebControls.GridDataItemCollection.get_Item(字符串分级索引)+37 Telerik.WebControls.RadGrid.get_EditItems() +215 c:\Projects\ACS\sample.Acs.Administration\UserControls\TaxManager.ascx.cs:88 中的 sample.Acs.Administration.TaxManager.rgStateTax_PreRender(Object sender, EventArgs e) System.Web.UI.Control.OnPreRender(EventArgs e) +8682870 System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +31 Telerik.RadGridUtils.RadControl.OnPreRender(EventArgs e) +36 Telerik.RadGridUtils.RadAJAXControl.OnPreRender(EventArgs e) +37 Telerik.WebControls.RadGrid.OnPreRender(EventArgs e) +40 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

这是 grid(rgstatetax) 预渲染事件

protected void rgStateTax_PreRender( object sender, EventArgs e )
    {
        if( rgStateTax.MasterTableView.IsItemInserted )
        {
            foreach( GridItem item in rgStateTax.Items )
            {
                item.Visible = false;
            }
        }

        if( rgStateTax.EditItems.Count > 0 )
        {
            foreach( GridDataItem item in rgStateTax.Items )
            {
                if( item != rgStateTax.EditItems[0] )
                {
                    item.Visible = false;
                }
            }
        }

用户界面中的代码

protected void ddlCountryTax_SelectedIndexChanged(对象发送者,EventArgs e) { long locationId = ddlCountryTax.SelectedItem.Value.AsLong();

        ContentAdministrationServiceClient client = null;
        List<DCTaxRate> taxRate = null;
        try
        {
            client = new ContentAdministrationServiceClient();
            taxRate = client.GetTaxRatesByCountryIdAndLocationTypeName( locationId, "State" );
            client.Close();
        }
        catch( FaultException )
        {
            AbortClient(client);
            throw;
        }

        rgStateTax.DataSource = taxRate;
        rgStateTax.Rebind();

    }

包装层中的代码

公共列表 GetTaxRatesByCountryIdAndLocationTypeName(long countryId, string locationTypeName) { DCTaxRateCollection taxRates = new DCTaxRateCollection(); taxRates.GetByCountryIdAndLoactionTypeName( countryId, locationTypeName );

        return taxRates.ToList();
    }

    public void GetByCountryIdAndLoactionTypeName( long countryId, string locationTypeName )
    {
        IBOTaxRateCollection iboTaxRates = new BOTaxRateCollection();
        iboTaxRates.GetByCountryIdAndLocationTypeName( countryId, locationTypeName );

        SetItems( iboTaxRates );
    }

在博层

    public void GetByCountryIdAndLocationTypeName( long countryId, string locationTypeName )
    {
        ISingleResult<TaxRate> taxRates = Database.TaxRateReadByCountryIdAndLocationTypeName( countryId, locationTypeName );
        PopulateCollection( taxRates );
    }

【问题讨论】:

    标签: asp.net drop-down-menu


    【解决方案1】:

    当下拉列表中的值列表不包括绑定到 SelectedValue 属性的值时,会发生这种情况。如果这是因为你有一个空值,你可以让数据适配器在字段为空时返回一个空字符串(如果这是问题的话) 然后在下拉列表中插入一个值来匹配:

    <asp:DropDownList ID="dd_bound" runat="server" AppendDataBoundItems="True">
        <asp:ListItem Value="" Text="Select one..." />
    </asp:DropDownList>
    

    注意 AppendDataBoundItems 值。

    【讨论】:

    • 我将 appenddatabounditems 设置为 true 仍然会出现同样的错误
    • 你知道绑定的值是什么吗?它是 null 还是其他不在列表中的值?
    • 将国家/地区集合/列表读取到下拉列表之外。这就是这里发生的事情..无论如何感谢 4 重播
    猜你喜欢
    • 1970-01-01
    • 2012-05-24
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多