We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Dropdown in Grid Issue

Hello,
 
I have issues with populating Dropdown in Grid, The Dropdown comes up with
'System.Collections.Generic.Dictionary`2[System.String, System.Object]  items populated in the dropdown list.
 
This is code at the controller
 

public class AdminController : Controller

{

private IChapterRepository repositoryChapter;

private IBranchRepository repositoryBranch;

public AdminController(IChapterRepository chapterRepository, IBranchRepository branchRepository)

{

this.repositoryChapter = chapterRepository;

this.repositoryBranch = branchRepository;

}

/// <summary>

/// Used for rendering the grid initially.

/// </summary>

/// <returns>Veiw page, it displays the Grid</returns>

public ActionResult Chapters()

{

 

ViewData[

"BranchCode"] = BranchList;

var data = repositoryChapter.Chapters.ToList();

return View(data);

}

public IEnumerable<SelectListItem> BranchList

{

get

{

List<SelectListItem> type = new List<SelectListItem>();

var branches = repositoryBranch.Branches;

foreach (var branch in branches)

{

type.Add(

new SelectListItem

{

Text = branch.BranchName,

Value = branch.BranchCode

});

}

return type;

}

}

....

 

CODE AT THE CSHTML

.Datasource(Model)

.ActionMode(Syncfusion.Mvc.Grid.

ActionMode.Server)

.Caption(

"Chapters").Scrolling(s => s.Height(300))

.Column(column =>

{

column.Add(c => c.ChapterId).HeaderText(

"Chapter ID").TextAlign(Syncfusion.Mvc.Grid.TextAlignment.Left).Width(100);

column.Add(c => c.ChapterName).HeaderText(

"Chapter Name").TextAlign( Syncfusion.Mvc.Grid.TextAlignment.Left).Width(100);

column.Add(c => c.ChapterFullName).HeaderText(

"Chapter Full Name").Width(130);

column.Add(c => c.BranchCode).HeaderText(

"Branch").CellEditType(CellEditType.DropdownEdit).Width(130).DropDownDataSource((System.Collections.IEnumerable)ViewData["BranchCode"]);

column.Add(c => c.EmailAddress).HeaderText(

"Email Address").Width(110);

})

.EnablePaging()

.EnableSorting()

.AutoFormat(Syncfusion.Mvc.Shared.

Skins.Marble)

.Caption(

"Chapters")

.ToolBar(tools =>

{

tools.Add(

GridToolBarItems.AddNew)

.Add(

GridToolBarItems.Edit)

.Add(

GridToolBarItems.Delete)

.Add(

GridToolBarItems.Update)

.Add(

GridToolBarItems.Cancel);

})

.Mappers(mapper =>

{

mapper.InsertAction(

"AddChapter")

.SaveAction(

"ChapterSave")

.DeleteAction(

"DeleteChapter");

})

.Editing(edit =>

{

edit.AllowEdit(

true)

.AllowNew(

true)

.AllowDelete(

true);

edit.PrimaryKey(key => key.Add(c => c.ChapterId));

})

)

 

PLEASE CAN YOU HELP, BEING STUCK FOR 4 DAYS

 


1 Reply

AM Abdul Matin M Syncfusion Team July 16, 2013 10:42 AM UTC

Hi Joseph,


Thanks for your interest in Syncfusion products.

 

I have created a sample based on your code snippet. Could you use that sample and reproduce the error if any. We have resolved your issue by giving the name of the dataTextField and dataValueField in DropDownDataSource method.

 

Please refer the below online documentation link:

http://help.syncfusion.com/UG/ASP.NET%20MVC/Grid/documents/databindingsupportfo.htm


For your convenience we have attached a sample and screenshot. Could you use that sample and get back to us if you have any queries.

 

Let us know if you have any concerns.

 

Regards,

Abdul Matin M

 



DropDown1_ba906b51.zip

Loader.
Live Chat Icon For mobile
Up arrow icon