views:

219

answers:

1

I need to insert a value into a selectlist. It isn't the "0" value (i.e. the first one that shows) but the next one which would be "Other". This is then used to display an "Other" textbox.

My question is similiar to link text.

EDIT: I don't know if this will help but here is the code:

        SelectList Titles;
        ViewData["TitleIsOther"] = TitleIsOther(Case);
        if ((bool)ViewData["TitleIsOther"])
        {
            Titles = new SelectList((LookupCollection)this.LookupRepository.FetchByCategory(true, 0, 0, false,
             (int)Enums.LookupCategory.CaseTitles, _LoggedInUser.AccountId), "Id", "Name", "-1");
        }
        else
        {
            Titles = new SelectList((LookupCollection)this.LookupRepository.FetchByCategory(true, 0, 0, false,
             (int)Enums.LookupCategory.CaseTitles, _LoggedInUser.AccountId), "Id", "Name");
        }
        ViewData["Titles"] = Titles;

The selected value of "-1" would be the "Other" option.

A: 

You can't add 2nd value in similar fashion as optionLabel parameter of Html.DropDownList() provides. You will have to generate SelectList manually.

This post might be useful.

Arnis L.