Insert value into selectlist
Posted
by William
on Stack Overflow
See other posts from Stack Overflow
or by William
Published on 2009-08-12T08:53:32Z
Indexed on
2010/04/18
22:03 UTC
Read the original article
Hit count: 530
asp.net-mvc
|selectlist
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.
© Stack Overflow or respective owner