views:

382

answers:

2

I have one dropdownbox(ddlCountryTax) containing allcountries,If i select USA it will display grid displaying Tax information related to USA.If i edit information in grid and if we change country USA to UK in dropdown box in the ddlCountryTax(not the dropdownbox coming in the edit window of grid,,no problem for that) it displaying error like

Specified argument was out of the range of valid values.
Parameter name: ItemHierarchicalIndex
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: ItemHierarchicalIndex

Source Error:

    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

Stack Trace:

[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

this is code dropdown event

    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();

    }

this is 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();
    }

this is grid pre render event 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;
                }
            }
        }
    }
A: 

Can you post the code from the Pre-Render event that is throwing the error?

cerhart
i posted my pre render event
peter
Is tere any thing problem
peter
A: 

My guess as to what is happening is that you have made changes in your grid and before commiting those changes you are changing the data in the grid.

It appears your processing of the changes in the grid are happening after the event to change the grid data. To fix this you either have to process any grid changes before changing the grid data, or throw away the grid changes when the country changes.

Daniel