0

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"
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

1SeoAdvies
  • 103
  • 1
  • 2
  • 10
  • What kind of table? Database table? – Narnian Jul 14 '11 at 14:30
  • And what is your point?? It doesnot matter to me! I only want some answer to my question(s). Most answers are not relevant! – 1SeoAdvies Jul 14 '11 at 15:37
  • @1SeoAdvies, I don't agree that most answers are not relevant. Here's an [example of one](http://stackoverflow.com/questions/6329288/rerouting-in-views-mvc3/6329342#6329342) in which you said that it helped you and yet it is not marked as answer. – Darin Dimitrov Jul 14 '11 at 15:46
  • 1
    @1SeoAdvies - you should be flagged, tagged and bagged! – gangelo Jul 14 '11 at 15:52

2 Answers2

1

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

Community
  • 1
  • 1
Pit Digger
  • 9,618
  • 23
  • 78
  • 122
0

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

gangelo
  • 3,034
  • 4
  • 29
  • 43