指定的参数超出了有效值的范围

时间:2009-04-02 12:15:13

标签: asp.net drop-down-menu

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

  

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

来源错误:

    Line 86: }
    Line 87:
    Line 88: if( rgStateTax.EditItems.Count > 0 ) 
    Line 89: { 
    Line 90: foreach( GridDataItem item in rgStateTax.Items )

    Source File: c:\Projects\ACS\Aivea.Acs.Administration\UserControls\TaxManager.ascx.cs Line: 88

堆栈追踪:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: ItemHierarchicalIndex]
Telerik.WebControls.GridItemCollection.get_Item(String hierarchicalIndex) +323
Telerik.WebControls.GridDataItemCollection.get_Item(String hierarchicalIndex) +37
Telerik.WebControls.RadGrid.get_EditItems() +215
Aivea.Acs.Administration.TaxManager.rgStateTax_PreRender(Object sender, EventArgs e) in c:\Projects\ACS\Aivea.Acs.Administration\UserControls\TaxManager.ascx.cs:88
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.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

这是代码下拉事件

    protected void ddlCountryTax_SelectedIndexChanged( object sender, 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 );
        }

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

    }

这是radgrid

   protected void rgStateTax_EditCommand( object sender, EventArgs e )
    {
        BindStateTax();
    }


 private void BindStateTax()
    {
        long locationId = ddlCountryTax.SelectedItem.Value.AsLong();

        List<DCTaxRate> taxRate = null;
        ContentAdministrationServiceClient client = null;
        try
        {
            client = new ContentAdministrationServiceClient();
            taxRate = client.GetTaxRatesByCountryId( locationId );
            client.Close();
        }
        catch( FaultException )
        {
            AbortClient( client );
        }

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

这是预渲染事件:

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;
                }
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

我对正在发生的事情的猜测是,您在网格中进行了更改,并且在提交这些更改之前,您正在更改网格中的数据。

在事件发生后,您可能会对网格中的更改进行处理以更改网格数据。要解决此问题,您必须在更改网格数据之前处理任何网格更改,或者在国家/地区更改时丢弃网格更改。