我有选择。正如您可能看到的,文本与值不同。
<select id="divPlatformsPopup" ClientIDMode="Static" runat="server" class="selectpicker col-md-12 ClassPad0" multiple title='Choose one of the following...' data-container="body" data-selected-text-format="count>2" data-style="btn-xs btn-default">
<option value="All">All Platforms</option>
<option value="Mobile Phone,Tablet,Windows Phone,PlayStation Certified Device,Windows 8 App,PlayStation Mobile">Mobile App/Tablet</option>
<option value="Nintendo DS,Nintendo DSi,Nintendo 3DS">Nintendo DS/DSi/3DS</option>
<option value="Playstation 3">Playstation 3</option>
<option value="PlayStation 4">PlayStation 4</option>
<option value="PSP,PS Vita">PlayStation Vita/PSP</option>
<option value="Wii">Wii</option>
<option value="Wii U">Wii U</option>
<option value="Linux,Macintosh,PC DVD,PC DVD-ROM,Windows CE,Windows PC,Windows 8 App">Windows/Mac</option>
<option value="Xbox 360">Xbox 360</option>
<option value="Xbox One">Xbox One</option>
<option value="3DO,Atari Jaguar,Atari Lynx,Cable Box,CDI,Dreamcast,DVD,Game Boy,Game Boy Advance,Game Boy Color,Game Gear,Game Wave(Custom DVD gaming platform),Game Cube,Gizmondo,Hyperscan,iPod,N-Gage,Neo Geo Pocket Color,Nintendo,Nintendo 64,Nintendo Game Boy,NUON,Online,Other,Palm Pilot,PDA(Palm, Win CE, etc.),PlayStation&2FPS one,Playstation 2,Plug-and-Play,Pocket Arcade,Pocket PC,Pokemon Mini,Sega 32x,Sega CD,Sega Dreamcast,Sega Genesis,Sega Pico,Sega Pocket Arcade,Sega Saturn,Super Nintendo,VG Pocket,Virtual Boy,Web Browser,Web Site,Web TV,Xbox,Zodiac,Firefox">Other Platforms</option>
</select>
我有一部分代码可以按值设置选定的值。
foreach (var li in platforms.Select(platform => divPlatformsPopup.Items.FindByValue(platform)))
{
li.Selected = true;
}
其中platforms
是所选值的列表
但这是一个我不算数的案例。可以将platforms
列表值作为select的值的一部分传入(例如&#34; Nintendo DS&#34;作为&#34的一部分; Nintendo DS,Nintendo DSi,Nintendo 3DS& #34;。)
我想知道如何选择包含选择项目的部分VALUE的项目。
答案 0 :(得分:0)
好吧,我找到了解决方案:
我为Select中的每个项目循环,并检查项目是否包含一些字符串
foreach (var platform in platforms)
{
for (var i = 0; i <= divPlatformsPopup.Items.Count; i++)
{
if (Array.IndexOf(divPlatformsPopup.Items[i].Value.Split(','), platform) > -1)
{
divPlatformsPopup.Items[i].Selected = true;
}
}
}