Remove the (none) option on state dropdown

Chetan Sharma asked on August 14, 2014 20:22

I would like to Remove the (none) option on state dropdown and replace it with a string like "Select State"

Where in this file ~/CMSFormControls/CountrySelector.ascx.cs I have to make changes?

Thanks Chetan

Recent Answers


Yehuda Lando answered on August 14, 2014 20:29

I think it's the uniSelectorCountry.NoneRecordValue property. Just make sure to copy the control, and not change the default one.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 14, 2014 21:09

I tried this. This is not working.

I changed this.uniSelectorCountry.NoneRecordValue = "Select State"

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on August 14, 2014 21:56 (last edited on August 14, 2014 21:56)

I think this is controlled by this property on the control:

/// <summary>
/// Add '(none)' record to the dropdownlist.
/// </summary>
public bool AddNoneRecord
{
    get
    {
        if (mAddNoneRecord == null)
        {
            mAddNoneRecord = ValidationHelper.GetBoolean(GetValue("AddNoneRecord"), false);
        }
        return (bool)mAddNoneRecord;
    }
    set
    {
        mAddNoneRecord = value;
    }
}

Then they fill it like this:

 if (AddNoneRecord)
                {
                    // Add (none) record when requested
                    uniSelectorCountry.SpecialFields.Add(new SpecialField() { Text = GetString("general.selectnone"), Value = string.Empty });
                }

So just changed the text value and you should be good to go. EXAMPLE: uniSelectorCountry.SpecialFields.Add(new SpecialField() { Text = "Select State", Value = string.Empty });

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 15, 2014 15:07

Thanks Joshua, however I was unable to find this code in my file. The syntax you gave me resulted in an error.

BTW, I'm working on kentico 7 and not the latest

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on August 15, 2014 15:45

That was for version 8...my bad, the code will be very similar, just find this section

string[,] fields = null;
        if (AddSelectCountryRecord && AddNoneRecord)
        {
            fields = new string[,]
                         {
                             { GetString("countryselector.selectcountryrecord"), "" },
                             { GetString("general.selectnone"), "" }
                         };
        }
        else
        {
            // Add 'none' record when requested
            if (AddNoneRecord)
            {
                fields = new string[,] { { GetString("general.selectnone"), "" } };
            }
        }

and change the values to match what you want. That should work...You may have to play around with which parts to change depending on your settings, or you could just change all of them.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 15, 2014 18:56

I tried various combinations but I failed to get what I want. I want to have "Select State" instead of "none" for State drop down beneath country

Thanks

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on August 18, 2014 15:47

Are you using the getstring method in yours? this method is used for values in the resx file, so if you aren't storing your values there, then you should be removing the getstring method and just typing in a string.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 18, 2014 21:45

Well I tried something like this and few other combinations

// Add 'none' record when requested if (AddNoneRecord) { fields = new string[,] { { "Select State", "" } }; } Though I was able to add "Select state" to the country's dropdown but was unable to make it work for State.

Could you help me with exact code that works for you? I am new to .NET coding.

Regards Chetan

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on August 18, 2014 22:00

try placing this in with the other code that was provided. The uniselectorstate is a uniselector containing the states

uniSelectorState.SpecialFields.Add(new SpecialField() { Text = GetString("general.selectnone"), Value = string.Empty });

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 19, 2014 17:48

Could you please provide kentico 7 compatible code?

Thanks

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on September 6, 2014 04:55

Can anyone urgently help me on this please?

Many thanks!!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.