Click here to Skip to main content
15,922,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using dropdownlist. my code is shown below:

C#
if (ddlDeposite.SelectedItem.Text == "Normal Savings")
        {
            int indexOfOnDepositForNormalSavings = -1;
            indexOfOnDepositForNormalSavings = ddlInterestCalculationPeriod.Items.IndexOf(ddlInterestCalculationPeriod.Items.FindByValue("5"));
            ddlInterestCalculationPeriod.Items.RemoveAt(indexOfOnDepositTypeForNormalSavings);

            int indexOfMaturity = -1;
            indexOfMaturity = ddlInterestCalculationPeriod.Items.IndexOf(ddlInterestCalculationPeriod.Items.FindByValue("6"));
            ddlInterestCalculationPeriod.Items.RemoveAt(indexOfMaturity);
        }
if (ddlDeposite.SelectedItem.Text == "Recurring Savings")
        {
            int indexOfOnDepositForRecuringSavings = -1;
            indexOfOnDepositTypeForRecuringSavings = ddlInterestCalculationPeriod.Items.IndexOf(ddlInterestCalculationPeriod.Items.FindByValue("5"));
            ddlInterestCalculationPeriod.Items.RemoveAt(indexOfOnDepositTypeForRecuringSavings);
        }




what i wanted is as user selects Normal Savings on ddlDeposite, cetain item of ddlInterestCalculationPeriod (say of index 5 and 6) is to be removed when user drops down on ddlInterestCalculationPeriod. similarly, as user selects Recurring Savings, certain it ddlInterestCalculationPeriod (say of index 5) is to be removed when user drops down on ddlInterestCalculationPeriod.. everything works fine when user selects normal savings or recurring savings on ddlDeposite for first time.. as user re selects normal savings or recurring savings on ddlDeposit, the index value ie indexOfOnDepositForNormalSavings, indexOfMaturity or indexOfOnDepositForRecuringSavings becomes -1. thus the error msg is
SQL
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

the event is selectedIndexChaged.. any help???
Posted
Comments
Thanks7872 4-Dec-13 2:20am    
Some times,to change the logic is better than to find a solution. I am not able to get why you are doing all this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900