Hi
I'm implementing dropdown list defaulting based on selection while editing/adding a row on a webdatagrid. I have the events firing for selected index changed and data bound, but can't seem to set the selected index, i've tried
ddlUnitID.EditorControl.Items[2].Selected = true; ddlUnitID.EditorControl.SelectedValue = ddlUnitID.EditorControl.Items[2].Value; ddlUnitID.EditorControl.SelectedItemIndex = 2;
all seem to not select the item in the dropdopdown on the editing row. I've tried this both on selection changed and ondatabound.
<ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="False" OnRowUpdating="WebDataGrid1_RowUpdating" AutoGenerateBands="true" ViewStateMode="Disabled" DataKeyFields="ID" Width="98%" OnRowAdded="WebDataGrid1_RowAdded" OnRowAdding="WebDataGrid1_RowAdding" OnRowsDeleting="WebDataGrid1_RowDeleting" > <Columns> <ig:BoundDataField Hidden="true" DataFieldName="ID" Key="ID" > <Header Text="ID" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Ordinal" Key="Ordinal"> <Header Text="Process No." /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="MaterialID" Key="Material"> <Header Text="Material" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="QTY" Key="GROSS"> <Header Text="Quantity" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="UnitQTYID" Key="UOM"> <Header Text="Unit" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="UnitQTY" Key="COUNT"> <Header Text="Weight" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="UnitID" Key="WUOM"> <Header Text="Weight Unit" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Comments" Key="NET"> <Header Text="Comments" /> </ig:BoundDataField> <ig:TemplateDataField Key="DeleteItem" Width="60px"> <Header Text="Delete" /> <ItemTemplate> <asp:LinkButton runat="server" ID="DeleteItem" Text="X" OnClientClick="DeleteRow(); return false;" /> </ItemTemplate> </ig:TemplateDataField> </Columns> <EditorProviders> <ig:DropDownProvider ID="ddlMaterialID"> <EditorControl ID="ddlMatID" runat="server" DisplayMode="DropDown" TextField="NAME" OnSelectionChanged="ddlMatID_SelectionChanged" ValueField="ID" DataSourceID="srcMaterial" AutoPostBackFlags-SelectionChanged="Async"> </EditorControl> </ig:DropDownProvider> <ig:DropDownProvider ID="ddlUnitID"> <EditorControl ID="ddlUnID" runat="server" DisplayMode="DropDown" TextField="UNIT_NAME" ValueField="ID" DataSourceID="srcUnit" OnDataBound="ddlUnitID_DataBound"> </EditorControl> </ig:DropDownProvider> <ig:DropDownProvider ID="ddlWUnitID" > <EditorControl ID="ddlWUnID" runat="server" DisplayMode="DropDown" TextField="UNIT_NAME" ValueField="ID" DataSourceID="srcWUnit"> </EditorControl> </ig:DropDownProvider> <ig:NumericEditorProvider ID="txtUOM"> </ig:NumericEditorProvider> <ig:NumericEditorProvider ID="txtQuantity"> </ig:NumericEditorProvider> </EditorProviders> <Behaviors> <ig:Activation /> <ig:Selection RowSelectType="Multiple" CellClickAction="Row" /> <ig:Sorting SortingMode="Single" Enabled="true" /> <ig:ColumnMoving> </ig:ColumnMoving> <ig:ColumnResizing> </ig:ColumnResizing> <ig:EditingCore> <Behaviors> <ig:CellEditing Enabled="true"> <EditModeActions EnableF2="true" EnableOnActive="true" MouseClick="Single" /> <ColumnSettings> <ig:EditingColumnSetting ColumnKey="ID" ReadOnly="true" /> <ig:EditingColumnSetting ColumnKey="Material" EditorID="ddlMaterialID" /> <ig:EditingColumnSetting ColumnKey="COUNT" EditorID="txtQuantity" /> <ig:EditingColumnSetting ColumnKey="UOM" EditorID="ddlUnitID" /> <ig:EditingColumnSetting ColumnKey="WUOM" EditorID="ddlWUnitID" /> </ColumnSettings> </ig:CellEditing> <ig:RowAdding Alignment="Bottom" EditModeActions-EnableOnActive="true" EditModeActions-MouseClick="Single" Enabled="true" > <AddNewRowClientEvents ExitedEditMode="WebDataGridView_ExitedEditMode" /> <ColumnSettings> <ig:RowAddingColumnSetting ColumnKey="ID" ReadOnly="true" /> <ig:RowAddingColumnSetting ColumnKey="Material" EditorID="ddlMaterialID" /> <ig:RowAddingColumnSetting ColumnKey="COUNT" EditorID="txtQuantity" /> <ig:RowAddingColumnSetting ColumnKey="UOM" EditorID="ddlUnitID" /> <ig:RowAddingColumnSetting ColumnKey="WUOM" EditorID="ddlWUnitID" /> </ColumnSettings> </ig:RowAdding> <ig:RowDeleting Enabled="true" /> </Behaviors> </ig:EditingCore> </Behaviors> <ClientEvents AJAXResponse="WebDataGridView_AJAXResponse" /> </ig:WebDataGrid>
Using 2013.2 ASP.net and C#.Thanks
Ten
Hello Ten!
Thank you for contacting Infragistics Developer Support!
You can set default selected index based on another dropdown editor on the client side using EnteredEditMode event.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
function WebDataGrid1_CellEditing_EnteredEditMode(sender, eventArgs) { // Check if the current column is the desired if not do nothing if (eventArgs.getCell().get_column().get_key() != 'SupplierID') { return; } // Get the column value on which you will do your restrictions for the current column var categoryId = eventArgs.getCell().get_row().get_cellByColumnKey('CategoryID').get_value(); var defaultSelected = null; // set desired value based on the other dropdown if (categoryId == 1) { defaultSelected = 1; } else { defaultSelected = 5; } // If there is default selected index set it if (defaultSelected) { var editor = eventArgs.getEditor(); editor.selectItem(editor.get_items().get_item(defaultSelected), true, true); } }
Review the attached sample, and let me know if I may be of any further assistance.
Thanks Denis I wanted to do it server side to avoid a post to our webservice (there have been timing issues doing it that way). I guess there is no way around it. I'll try it from the client side.
i can't use eventargs because it's on the selected index changed of a different dropdown not on line edit. the event args is the current dropdown 'Material', i need to update the drop down 'WUOM'. I need to get the WUOM dropdown by reference and set it. there must be a selector other then eventarg to get a editor?
Hello,
Please provide a code sample of your scenario.
Thank you in advance.
function WebDataGrid1_CellEditing_ExitedEditMode(sender, eventArgs) { if (eventArgs.getCell().get_column().get_key() != 'Material') { return; }//did we just change the material, would rather this was on selected index changed but edit mode exit is ok for now //fetch the selected material id obj = { MaterialID: eventArgs.getCell().get_row().get_cellByColumnKey('Material').get_value() } //call the webservice fetch the unitid value POST("WebService.asmx/GetEngineMaterialUnit", JSON.stringify(obj), function (JSONCallback) { if (typeof JSONCallback === 'undefined' || JSONCallback === null) { alert('An error occured while fecthing the material unit.'); } else { if (JSONCallback.ID > 0 ) {//returns the unit value // set desired value based on the other dropdown var editor = eventArgs.getCell().get_row().get_cellByColumnKey('WUOM'); //get the unit dropdowneditor this seems to only get the header cell editor.selectItem(editor.get_items().get_item(JSONCallback.Units.ID), true, true); //this needs to be select buy value or text if possible //otherwise select by index would work i just need to get the dropdown editor and iterate through it to get the index then select it } } }); }
TypeError: editor.get_items is not a function EngineCompManage.aspx:645
Thank you for the provided code!
I looked into it, but I cannot identify the source of the issue. In order to identify I need a working code sample, replicating issue of your scenario, focusing only on the part causing the issue, so I can be able to debug it and be able to help you.
Attach the sample in your forum post reply as zip archive containing only the necessary aspx, cs, and js files. It will be even better if you modify the my attached sample and then attach it to this thread.
Thank you in advance!
I figured out what I needed, I found the function set_value that seems to both set the cell and the dropdown list
if (defaultSelected) { var dropdowntochange = eventArgs.getCell().get_row().get_cellByColumnKey('SupplierID'); dropdowntochange.set_value(defaultSelected); }
oh you can add this to the project you posted if you want, this is the functionality i was looking for ...
function WebDataGrid1_CellEditing_ExitedEditMode(sender, eventArgs) {
//using Exit Edit in place of onselectedindex changed if (eventArgs.getCell().get_column().get_key() != 'CategoryID') { return; } //when you edit CategoryID //Get the new value var categoryId = eventArgs.getCell().get_row().get_cellByColumnKey('CategoryID').get_value(); var defaultSelected = null; // set desired value based on the other dropdown if (categoryId == 1) { defaultSelected = 1; } else { defaultSelected = 5; } if (defaultSelected) { var dropdowntochange = eventArgs.getCell().get_row().get_cellByColumnKey('SupplierID'); //update the dropdown cell value
//TODO: might want to check if it has a selected index before we force an update
dropdowntochange.set_value(defaultSelected); } }