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

How to bind the current data to grid when edit button is pressed

1 Answer 41 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 12 May 2015, 06:22 PM

I have a grid with data on it. When I want to edit the data, I need to press the edit button and a new edit form will open with the current data from the row.

For the textboxes I use: 

@Html.EditorFor(model => model.SubStatus)

Now the issue is the dropDownList. Here is my code. the initial value is always blank?

CSHTML code:

@(Html.Kendo().DropDownListFor(m => m.SubType)
                .Name("SubsType") 
                .DataTextField("SubType1")
                .DataValueField("SubType_ID") 
                .DataSource(source =>
                {
                    source.Custom()
                          .ServerFiltering(true)
                          .Type("aspnetmvc-ajax")
                          .Transport(transport =>
                          {
                              transport.Read("GetType", "Welcome");
                          })
                          .Schema(schema =>
                          {
                              schema.Data("Data")
                                    .Total("Total"); 
                          });
                })
            )

 

Razor code:

 public JsonResult GetSubType([DataSourceRequest] DataSourceRequest dropDownRequest)
        {
            IList<SubType> myViewModels = new List<SubType>();

            foreach (SubType subType in db.ExecuteStoredProcedure<SubType>("proc_getType", null))
            {
                SubType subtype = new SubType()
                {
                    SubType_ID = subType.SubType_ID,
                    SubType1 = subType.SubType1
                };
                myViewModels.Add(subtype);
            }
            return Json(myViewModels.ToDataSourceResult(dropDownRequest), JsonRequestBehavior.AllowGet);
        }

Right now I get the list from the database. when the dropdownlist is pressed. but I want to set the initial value of the list to be the current value. How to do it?

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 14 May 2015, 08:56 AM
Hello Victor,

The problem you are experiencing is related to the fact that the name is overridden by the Name method. When strongly-typed extension is used (For<T>) then Name is not required. You can find more details here.

Regards,
Georgi Krustev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DropDownList
Asked by
Victor
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or