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
Hi,
Update:
What I did , I commented the last 4 lines of javascript
var dropdown = ''//.........;
dropdown.set_currentValue(selecedRowValue, true);
dropdown._elements["Input"].focus();
dropdown.closeDropDown();
and clicking on grid inside dropdown is setting the cell value and making row masked as edited. I am not able to select any other row's dropdown for some time.
Also, I noticed that after doing some change, when I save data, page gets post back to refresh the grid ..and in post back, the department dropdown is not showing the grid..
Request you to help here..
Hi..
It worked.. Removing DataBind() actually worked..
last help needed on this one..
Now as grid is coming in the dropdown, last requirement is that as soon as I select a row, the 2nd column value get set to the grid cell and the dropdown should get closed.
I added this js function
function WebDataGrid1_RowSelectionChanged(sender, eventArgs) {
var selectedRow = eventArgs.getSelectedRows().getItem(0);
var selecedRowValue = selectedRow.get_cell(1).get_value();
var grid = ig_controls.dgKeyWords;
var cellEditing = grid.get_behaviors().get_editingCore().get_behaviors().get_cellEditing()
var cell = cellEditing.get_cellInEditMode();
cell.set_value(selecedRowValue);
cellEditing.exitEditMode();
//I am not able to get the dropdown instance from javascript
}
I am not able to get the dropdown from this function here
Please let me know how this can be done..
Regards
Hello,
Thank you for your feedback.
I was able to reproduce this using 14.1.20141.2150 version and it seems like a wrong behavior. However you can avoid it if you do not call myGrid.DataBind() and app will work fine.
You can also upgrade at no cost to 14.1.20141.2392, where this behavior is fixed. The service release of 2392 is available for you to download at Infragistics website under My Keys & Downloads:
https://ko.infragistics.com/my-account/keys-and-downloads ( You need to click on the Product Name and then go to the Service releases tabs)
Please let me know if you have further questions on the matter.
Hi Hristo ,
I downloaded the sample you provided. Converted the Infragistics version to 14.1 (using version utility) as I have licence for that.
When I run the page and select the 'Department' from the dropdown, getting the same error
Check two images attached:
1. Screen1: when page loads for the 1st time
2. Page2: as soon as I select the dropdown value, the error page.
It is giving error at myGrid.DataBind()...
NOTE: I have just changed the Infragistics version from 14.2 to 14.1.. Attaching the same codebase you sent with Infragistics version14.1
Looking forward for your response ...
Hello Varun,
I was not able to reproeuce this error, actually the code worked fine. Please pay attention the where I add this line:
I guess you have placed it somewhere else and it causes the error. Also, when using this approach you would not need to bind the DropDown to a dataSource, since the WebDataGrid will be displayed for each item. I suggest that you just add one item to the dropdown.
Please review the modified sample and let me know if it meets your requirements.