This is a migrated thread and some comments may be shown as answers.

[Solved] Need help using dropdownlist

0 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bill
Top achievements
Rank 2
Bill asked on 13 Nov 2011, 07:42 AM

I am using version 2011.2.712.340 of the Telerik MVC 3 controls.

I simply want to be able to:
- set the selected value in the dropdownlist to a value coming back from the database
- list the items coming back from the database

- set the selectedindex for saving into the database

I don't know how to set the SelectedIndex and Value properties inside this user control.



<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Category>" %>

<%= Html.Telerik().DropDownList()
        .Name("CategoryDropDownList")
            .SelectedIndex()
            .Value(ViewBag.CategoryIdFromDB.ToString())
            .DataBinding(databinding => databinding.Ajax().Select("SelectCategories", "Category"))
%>
 



My View is set up to call the above shared control as follows:

columns.Bound(o => o.ProjectID).Hidden(true);
ViewBag.ProjectID = "<#= ProjectID #>";
columns.Bound(o => o.CategoryID).EditorTemplateName("Category");


The Select statement above in my Shared Editor Template is used to call an Action method in my Category controller as follows.

public ActionResult SelectCategories()
        {
            ViewBag.CategoryIdFromDB = db.GetCategoryIDByProjectID(ViewBag.ProjectID);
            IEnumerable<YeagerTechModel.Category> CategoryList = db.GetCategories();

            return new JsonResult { Data = new SelectList(CategoryList.ToList(), "CategoryID", "Description") };
        }

 

Tags
Grid
Asked by
Bill
Top achievements
Rank 2
Share this question
or