开发者

filling dropdownlist

I need to fill a dropdownlist with values from a settings table in a database.

(id int, code string, description string, value string)

1 , 1 , "something" , "This1"

2 , 1 , "this too" , "This2"

3 , 2 , "something else" , "This2"

开发者_如何学C n , x , and so on.......

Now I only want to fill the dropdownlist with code 1 (I want to use this on a lot of pages.)

How can I do this?? url to a tutorial or something like is also ok! btw I am using mvc3. cheers


If regular dropdown than as below

 using (DBContext context = new DBContext())
        {
            dropdown1.DataSource = context.settings .ToList();
            dropdown1.DataTextField = "code";
            dropdown1.DataValueField = "id";
            dropdown1.DataBind();
        }

If using MVC ?

http://www.c-sharpcorner.com/UploadFile/2124ae/5628/

Create a Dropdown List for MVC3 using Entity Framework (.edmx Model) & Razor Views && Insert A Database Record to Multiple Tables


If you want it across multiple pages, you want to also look in to Partial Views:

http://rachelappel.com/razor/partial-views-in-asp-net-mvc-3-w-the-razor-view-engine/ http://davidhayden.com/blog/dave/archive/2011/01/05/ASPNETMVC3TutorialsIndex.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜