Digital Marketing Strategies
How to bind the Dropdwon staticlly and Dynnamiclly in C# back end.

How to bind the Dropdown staticlly and Dynnamiclly in C# back end.

In this Article, i would like to show how to bind dropdown static and dynamic  from back end.

For Static:

private void BindDropDowns()
        {
            List<CommonModel> list = new List<CommonModel>();
            var obj = new CommonModel();
            //obj.Id = 1;
            //obj.Title = "Option 1";
            //list.Add(obj);
            obj = new CommonModel();
            obj.Id = 2;
            obj.Title = "Option 2";
            list.Add(obj);
            obj = new CommonModel();
            obj.Id = 3;
            obj.Title = "Option 3";
            list.Add(obj);
            obj = new CommonModel();
            obj.Id = 4;
            obj.Title = "Option  4";
            list.Add(obj);
            obj = new CommonModel();
            obj.Id = 5;
            obj.Title = "Option 5";
            list.Add(obj);
            obj = new CommonModel();
            obj.Id = 6;
            obj.Title = "Covid-19 Sitreps";
            list.Add(obj);
            obj = new CommonModel();
            obj.Id = 7;
            obj.Title = "Other Publications";
            list.Add(obj);
            //obj = new CommonModel();
            //obj.Id = 8;
            //obj.Title = "Videos";
            //list.Add(obj);


            ViewBag.TypeName = new SelectList(list, "Id", "Title");
        }

 

For Dynamic:

private void BindDropDown()
        {
            var cntry = _storedb.Countries.ToList();
            ViewBag.CountryLsit = new SelectList(cntry, "CountryID", "Name");

            var city = _storedb.Cities.ToList();
            ViewBag.CityList = new SelectList(city, "Id", "title");

            var ent_puprose = _storedb.EntityPuproseIds.ToList();
            ViewBag.ent_puproseList = new SelectList(ent_puprose, "Id", "title");


        }



Copyright Future Minutes © 2015- 2024 All Rights Reserved.   Terms of Service  |   Privacy Policy |  Contact US|  Pages|  Whats new?
Update on: Dec 20 2023 05:10 PM
03
07

New Messages

George Floyd
  • Edit Post Edit This Post within a Hour
  • Hide Chat Hide This Post
  • Delete Chat If inappropriate Post By Mistake
  • Report Inappropriate Chat
  • 4.5kb
  • Hi James! Please remember to buy the food for tomorrow! I’m gonna be handling the gifts and Jake’s gonna get the drinks
  • Hi James! Please remember to buy the food for tomorrow! I’m gonna be handling the gifts and Jake’s gonna get the drinks
  • Hi James! Please remember to buy the food for tomorrow! I’m gonna be handling the gifts and Jake’s gonna get the drinks