Thursday, 21 July 2016

Drop Down List Default Selected Value in MVC C#.

Controller:
DataTable dt = new DataTable();
            dt.Columns.Add("Value", typeof(int));
            dt.Columns.Add("Text", typeof(string));
            dt.Rows.Add(1, "Arul");
            dt.Rows.Add(2, "Kumar");
            dt.Rows.Add(3, "Arulkumar");
           

            ViewBag.DDL = new SelectList(dt.AsDataView(), "Value", "Text",2);
//where 2-for selected value Kumar
View
//DDL is viewbag name
@Html.DropDownList("DDL ", null, htmlAttributes: new { @class = "form-control" })

No comments:

Post a Comment