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 Team,,
Attaching the codebase I am working on..
Check the method GetDepartment. It is returning a data table with three columns : ID, Department Name, Owner
Select the grid type as 'Department' and it will load the department data.
Check the column 'Department Name', it is having a dropdown editor provider with single column..
I need to show there the full GetDepartment data table and selection of row , the value should set to the cell
Regards
Hello Varun,
Thank you for the working sample attached. I will try to reproduce the issue using the code from your post and will suggest accordingly. I will keep you posted with my findings.
1) You can get reference to the dropdown as follows:
var dropdown = ig_controls.dgKeyWords_ctl01 (after typing ig_controls. in the console IntelliSense will show the available ones)
2) Also, the dropdown provider need to be added on PageLoad event. In your case, this happens only on SelectionChanged event and when you hit the Save button the SetGridBehaviors method is not called. You need to change this logic as to call SetGridBehaviors method on Page_Load.
3) I am not able to select any other row's dropdown for some time
There is onky one instance of the WebDropDown, it just initializes itself only on the current cell that is being edited.
Please let me know if you have further questions on the matter.
Point 1 and 3 has been fixed..
Point 2:
I moved SetGridBehaviors on page load and now sees a new issue..
The webgrid inside dropdown editor provider is getting added one after another..After two post back, I saw 2 grids inside the dropdown...
I would like to request you to modify the previously attached solution so that it retains the grid inside dropdown after postback
Also, i thought of keeping everything inside update panel so it will not fire full psot back. Doing so I will retain the dropdown's grid..
In this case what I observed that the edited row indicator (converting text to italics) remains as it is .. it is not getting back to normal post save as it is not doing full post back..
Any idea??
Hello,
I have further modified my sample in order to fix Issue 2. The following requirements had to be followed fo fix Issue 2:
1) Grid behaviors are created in the Page_Init event
2) The DropDown provider is created just once in Page_Load event
3) The item template needs to be re-created on every postback.
I have also simplified it and now only one DropDown provider is created and it is being set depending on the selected value in the dropdown.
Please review the sample and let me know if you have any further questions on the matter.
Hi Hristo ,
AWESOME....!!! You saved my day...
Thanks a lot for your assistance and continuous support...
Support team like this makes a great product :)
Cheers
Hi,
I am glad this helped ! :)
Please do not hesitate to contact us if you have any further questions on the matter !