Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
865
Multic Column Dropdown + grid Bind Issue
posted

Hi Team, 

I have a dropdown inside a web data grid column as editor provider.

This is how I am adding the dropdown to the grid column as editor provider

----------------------------------------------------------------------

DropDownProvider provider = new DropDownProvider();
provider.ID = "ddlDepartment";
provider.EditorControl.DropDownContainerWidth = 150;
dgKeyWords.EditorProviders.Add(provider);

((DropDownProvider)dgKeyWords.EditorProviders["ddlDepartment"]).EditorControl.DataSource = GetDepartment();
((DropDownProvider)dgKeyWords.EditorProviders["ddlDepartment"]).EditorControl.TextField = "Department Name";
((DropDownProvider)dgKeyWords.EditorProviders["ddlDepartment"]).EditorControl.ValueField = "ID";
((DropDownProvider)dgKeyWords.EditorProviders["ddlDepartment"]).EditorControl.DataBind();

----------------------------------------------------------------------

Till now it is working as my method 'GetDepartment' was returning data in ID-NAME format and it was required to show only one column to dropdown

Now the requirement is to show multiple columns inside the dropdown editor provider and method 'GetDepartment' will return 3 columns (ID, Dep Name, Dep Owner)

dropdown will show all the three values and selection of same, the dep name will be set to cell value.

NOTE that I have managed to do this by adding editor provider via aspx and adding code to add multi column to drpodnw via code behind.

Scenario now is that dropdown provider is getting added via codebase but not sure how to set multi column dropdown here.

I tried with this  :
addition of another line to set item template 

 ((DropDownProvider)dgKeyWords.EditorProviders["ddlDepartment"]).EditorControl.ItemTemplate = new multiColumnTemplate();

private class multiColumnTemplate : ITemplate
{


public void InstantiateIn(Control container)
{
//Create a new WebDataGrid
Infragistics.Web.UI.GridControls.WebDataGrid myGrid = new Infragistics.Web.UI.GridControls.WebDataGrid();
myGrid.ID = "templateGrid";

myGrid.DataSource = new Page1().GetDepartment();
myGrid.DataBind();


myGrid.Behaviors.CreateBehavior<Selection>();
myGrid.Behaviors.Selection.CellClickAction = CellClickAction.Row;
myGrid.Behaviors.Selection.RowSelectType = SelectType.Single;



myGrid.Behaviors.Selection.SelectionClientEvents.RowSelectionChanged = "WebDataGrid1_RowSelectionChanged";

container.Controls.Add(myGrid);

}
}

I am getting error on line : myGrid.DataBind(); that is 'Object Reference not set to an instance....'

Please help

Varun

Parents Reply Children