I have a WebDataGrid where the first field uses a dropdown provider. Whenever the user selects an item from the dropdown, I need to automatically select an item in another dropdown field and set 2 other fields, depending on what was selected. I need to be able to get a record from the database for the selected item to determine what the other fields should be. Is there a way to call a server method when the user selects from a dropdown where I can determine what was selected and be able to set the other fields? If not, what is the best way to accomplish this?
Thanks,
Jeff
Hello Jeff,
Thank you for the details provided. Refer to the link below that will give more details on how to cascade WebDropDown control:
<http://help.infragistics.com/NetAdvantage/ASPNET/2011.2/CLR4.0/?page=WebDropDown_Cascading_WebDropDown_Controls.html>
The same approach can be taken from the dropdownprovider.
I hope this helps.
I am not sure how to use the example with a DropDownProvider. How do you specify the ItemsRequested server-side event for the DropDownProvider? Also, I want to set the selected item for one row. Using the example, it would just change the items in the list and it would be for all rows.
I have attached a markup and code behind that implements this functionality. You can specify Item requeted event for the cascaded dropDownprovider as shown below:
<EditorControl DropDownContainerMaxHeight="200px" EnableAnimations="False" runat="server" ID="provider2" OnItemsRequested="eProvider_ItemsRequested" DropDownContainerWidth="180" EnableDropDownAsChild="False"> <Button AltText="" /> </EditorControl>
You can access Editor Control programmatically and handle OnItemsRequested at runtime also. In the attached sample the “Description” column will populate its values based on the “CatagoryName” column dropdown editor.
When I tried this, the dropdown list for every row was changed to only contain. I only want the dropdown in the current row to be changed. Also, I do would prefer to only set the selected item in the list, not filter the list.
Your example only sets one field. What I need to do is set 3 fields when an item in the dropdown is selected. Two of these are text fields and the other is a dropdown. Can I get the editor of the 3 fields following the dropdown filed so that I can set their values?
Yes, you can set multiple dropdown I would recommend you to handle EnteredEditMode event CellEditing event and call loadItems method based on the text of the cell text of the parent cell as shown below:
function loadDropDownItems(sender, args) {
var previousCell = args._cell._row.get_cell(args._cell.get_index() - 1);
if (args._editor._id == 'WebDataGrid1_provider2') {
args._editor.loadItems(previousCell.get_text());
}
if(args.getCell().get_index()==3)
{
var previousCell1 = args._cell._row.get_cell(args._cell.get_index() - 2);
if (args._editor._id == 'WebDataGrid1_provider3') {
args._editor.loadItems(previousCell1.get_text());
This is not what I need. I want to set the selected item in the list, not filter the list. Also, I need the values set when the selection of the parent cell has changed, not when the user enters the child cell. When selecting an item from the parent, I need to change the selected item in a dropdown in another cell and set the value of 2 other fields that are text fields. In the ItemsRequest server method, I tried the following:
WebDropDown wdr = (WebDropDown)sender; wdr.Items.Clear(); dsProjects.SelectCommand = "SELECT [ProjectID], [ProjectName] FROM [Projects]"; wdr.TextField = "ProjectName"; wdr.ValueField = "ProjectID"; wdr.DataBind(); wdr.SelectedItemIndex = 3;
This did not work as the selected item was not changed.
I was able to see that items in dropdown open near the upper left part of the window. I modified the code as shown below:
function WebDataGrid1_DropDown_ItemsRequested(sender, eventArgs) { if (document.readyState != "complete") { window.setTimeout("WebDataGrid1_DropDown_ItemsRequested()", 500); } else {
var grid = $find("WebDataGrid1"); var item = grid._editorProviders._items[1]._editor.get_items().getItem(0); grid._editorProviders._items[1]._editor.selectItemByIndex(0, true, true); } }
It still opens dropdown near the upper left part of the window briefly. I am looking in to this behavior. I have opened a new private support case CAS-102672-J0F0P5 for you. I will update you further with more details on this support case.
Attached is your sample, modified to show the problem.
In order to look in to this please provided me with the modified sample I have provided on Tue, Oct 23 2012 1:55 PM that demonstrates this behavior.
I am not able to get this to work. I am using the ExitingEditMode client event with the following code to fire the ItemsRequested server event for a different column.
if (eventArgs._editor._id == 'WebDataGrid1_Project_Provider') { //eventArgs._editor.loadItems(previousCell.get_text()); var grid = $find("WebDataGrid1"); grid._editorProviders._items[2]._editor.loadItems(previousCell.get_text()); }
Currently, the ItemsRequested server side event does nothing. It will get the default value to be selected from the database. In the client side ItemsRequested event for the field that I want to set the selected value for, I have the following:
var grid = $find("WebDataGrid1"); grid._editorProviders._items[2]._editor.set_activeItem(grid._editorProviders._items[2]._editor.get_items().getItem(1));
What is happening is the dropdown for this field opens near the upper left part of the window. It does have the desired item highlighted. When selecting anything from that dropdown list, the dropdown disappears, but nothing is changed in the grid. If I click in other cells, I can updated them, but the dropdown stays visible until I select an item in the list.
You can handle ItemsRequested event on the client side of the dropdown provider which fires after server side ItemsRequested event fires and before page loads. In this event you can get the instance of editor provider and set the active item in the drop down provider based on your requirements.
var cellindex;
function loadDropDownItems(sender, args) { cellindex= args.getCell().get_index(); if (cellindex == 2)
{ var previousCell = args._cell._row.get_cell(args._cell.get_index() - 1); if (args._editor._id == 'WebDataGrid1_provider2') { args._editor.loadItems(previousCell.get_text()); } } }
function WebDataGrid1_DropDown_ItemsRequested(sender, eventArgs) { var grid = $find("WebDataGrid1"); grid._editorProviders._items[1]._editor.set_activeItem(grid._editorProviders._items[1]._editor.get_items().getItem(1));
I have hard coded some values in the above code. You can use cellindex variable to set selected items.