Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public ActionResult Index()
        {
            var ListItms = dl.BindItems();
            List<SelectListItem> items = new List<SelectListItem>();
            foreach (var itms in ListItms)
            {
                SelectListItem s = new SelectListItem();
                s.Text = itms.ItemCode.ToString();
                s.Value = itms.ItemName.ToString();
                items.Add(s);
            }
            ViewBag.Campaign = items;

            return View();

And here is View:
SQL
@using (Html.BeginForm("Index", "Testing"))
{
    @Html.DropDownList("ItmName", new SelectList(ViewBag.Campaign, "Value", "Text"))
}

Now I have added another DropDownList ,on below DropDownList i want to change its value as per ItmCode selectedIndex
SQL
@Html.DropDownList("ItmCode", new SelectList(ViewBag.Campaign, "Text", "Value"))
Posted
Comments
F-ES Sitecore 3-Jun-15 5:06am    
Google "mvc cascading dropdowns" for examples. SelectedIndexChanged is a webforms concept, it doesn't exist in MVC, you'll need to generate your own javascript to submit the form when the values change, or just use a pure ajax solution. Googling should find examples of both.
xibit89 3-Jun-15 5:50am    
Thanks. I'll try cascading dropdowns.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900