本文介绍了MVC -DropDownList - 分类 - 子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库我有tbales:categoreis和SubCategoreis。我想创建一个DROPDOWNLIST containg这两种。是这样的:

In my database I have tbales: categoreis and SubCategoreis. I would Like to create one Dropdownlist containg both of these. Something like:


    «Välj资讯»

«Välj»

<option value='1000' style='background-color:#dcdcc3;font-weight:bold;' id='cat1000' >

			-- FORDON --    /// this is from Categoreis Table

	</option> 

<option value='1020'  id='cat1020' >
		Bilar                    /// this is from SubCategoreis

	</option> 

<option value='1040'  id='cat1040' >
		Bildelar & Biltillbehör   /// this is from Categoreis

	</option> 

<option value='1060'  id='cat1060' >
		Båtar                   /// this is from Categoreis

	</option> 

<option value='1080'  id='cat1080' >
		Båtdelar & tillbehör   /// this is from Categoreis

	</option>

任何样品,我怎么能解决这个问题?我应该用助手或MVCUsercontrol?我认为,缓存在这个case.Help我importatnt了!
谢谢!

Any samples how I could solve this? should I use Helpers or MVCUsercontrol??? I think that caching is importatnt in this case.Help me out !Thanks!!

推荐答案

Frajer,

您需要创建一个OPTION和OPTGROUP元素的SELECT列表。这里的格式,你在找什么:

You need to create a SELECT list with OPTION and OPTGROUP elements. Here is the format of what you are looking for:

<select>
<option value="">[Please select an option]</option>
<optgroup label="Group 1">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
</optgroup>
<optgroup label="Group 2">
    <option value="3">Option 3</option>
    <option value="4">Option 4</option>
</optgroup>
<optgroup label="Group 3">
    <option value="5">Option 5</option>
    <option value="6">Option 6</option>
</optgroup>
<optgroup label="Group 4">
    <option value="7">Option 7</option>
    <option value="8">Option 8</option>
</optgroup>

勾选此博客文章。这表明在普通文本加粗和类别的项目类别。笔者创建了一个MVC扩展处理这个问题。

Check this blog post. It shows categories in bold and category items in regular text. The author creates an MVC extension to handle this.

http://weblogs.asp.net/raduenuca/archive/2011/02/26/asp-net-mvc-extending-the-dropdownlist-to-show-the-items-grouped-by-a-category.aspx

这篇关于MVC -DropDownList - 分类 - 子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 20:58