Hi!
I have a grid with Row Adding enabled. I have defined DropDownProviders to some columns. What I haven't been able to implement is a way to get values from other dropdowns on the page as default values of the Insertion Row dropdowns. Here's the detailed explanation of the situation:
- I have dropdown on my page which binds to a datasource (say _ddProject)
- I have databound grid with Project as one column
- I have DropDownProvider in the Insertion Row which uses the same datasource than _ddProject
How can I use the _ddProject.SelectedValue as the selected value of Insertion Row dropdown?
Dropdowns have CurrentValue, but I haven't been able to set it by using code like this:
<ig:DropDownProvider ID="BranchProvider">
<EditorControl EnableDropDownAsChild="False" DataSourceID="SqlDataSource" TextField="name" ValueField="name" CurrentValue='<%= _dropdown.SelectedValue %>'>
<DropDownItemBinding TextField="name" ValueField="name"/>
</EditorControl>
</ig:DropDownProvider>
Is it possible to set the CurrentValue to match a value of a control somewhere on your page or do I have to do this on client side on TemplateOpened event?
Hello AriV,
The current value is automatically set to the editor control of the DropDownProvider for each cell. When using "<% =" and "%>" is for getting a particular field in the datasource databind to however the grid will automatically set the current value of the dropdown.
I attached a sample for this in particular.
Let me know if you have any questions with this matter. Thank you.
Your solution seems to have everything to do with row editing where you already have data, but I am talking about insert row which (of course) doesn't have data bound to it. I know how to get data bound to the dropdowns on insert row, but this far I have failed to actually SELECT anything from the dropdowns.
I am doing at the moment the selection on code behind in DataBinding and just in case in PreRender event. If I check out the values in the Provider I see clearly that something has been selected.
SelectedItem: {Foobar}SelectedItemIndex: 3SelectedItems: Count = 1SelectedValue: "Foobar"Sort: "name"TextField: "name"ValueDisplayType: SimpleValueField: "name"
There is no selection on dropdown on the interface, but if I set the tooltip to be the SelectedValue I can see that on interface.
What are my options? Set the default value on client side?
In the RowAdding client side event you can set the inner text of the cell's element of the row add record:
function WebDataGrid1_RowAdding_EnteringEditMode(sender, eventArgs){ ///<summary> /// ///</summary> ///<param name="sender" type="Infragistics.Web.UI.WebDataGrid"></param> ///<param name="eventArgs" type="Infragistics.Web.UI.CancelEditModeEventArgs"></param> eventArgs.getCell().get_element().innerText = 'Hello 2';}
eventArgs.getCell().get_element().innerText = 'Hello 2';}
Hi Duane and thanks for putting some time to reply, but you seem to misunderstand me. I have been talking about getting PREselected values to the insert row when the grid has been loaded. In previous mails you have been talking first about totally different thing. Here's the question from my first message:
Here's the detailed explanation of the situation:
How can I use the _ddProject.SelectedValue as the selected value of Insertion Row dropdown? I want the user to have something ALWAYS selected in the insert row and that something should be based on dropdown selections on the page (in this example _ddProject).
Attached is a sample I created for adding a column as a DropDownProvider to the grid and enable row adding. When entering edit mode of the AddNewRowClientEvents contains the EnteringEditMode client side event. When handling this will fire when entering the edit cell of the new record. This will set the inner text of the html contents of the cell and automatically have the dropdown select to the particular item by it's text.
The main reason of handling the EnteringEditMode of the AddNewRowClientEvents is because the dropdown does not appear until after going into edit mode.
From my understanding on the particular scenario described I believe this is what you would like in the grid. Take a look at the attached sample.
Thanks a lot AriV and Duane! Using a combination of both of your answers I was able to do exactly what I needed to do. If they enter edit mode and the dropdown has no value it defaults it to "M", then if they change it to a value other than M it clears certain cells and blocks those cells from being edited.
function
wdgEQMonPointsList_EnteringRowAddingEditMode(sender, eventArgs) {
var editCell = eventArgs.getCell();
var row = editCell.get_row();
var pointTypeCell = row.get_cellByColumnKey("PNT_TYPE");
if (pointTypeCell.get_value() == "") {
pointTypeCell.set_value(
'M','Measurement');
}
if (pointTypeCell.get_value() != "M") {
ClearReadingCells(row);
switch (editCell.get_column().get_key()) {
case "PNT_UOM":
case "ALRT_UPPER":
case "ALRT_LOWER":
case "WRN_UPPER":
case "WRN_LOWER":
case "WRN_TEXT":
eventArgs.set_cancel(
true);
break;
default:
ClearReadingCells(row) {
row.get_cellByColumnKey(
"PNT_UOM").set_value(null);
"ALRT_UPPER").set_value(null);
"ALRT_LOWER").set_value(null);
"WRN_UPPER").set_value(null);
"WRN_LOWER").set_value(null);
"WRN_TEXT").set_value(null);
Your post took me to the right direction, Duane. In the end the implementation took 5 minutes.
// Get the cell we clicked. var cell = eventArgs.getCell(); // Get the row of that cell (which is insert row). var row = cell.get_row();
// Get values from a dropdown on a page (with ClientIDMode="Static"). var dropdown = document.getElementById("_ddSelection"); var dropdownValue = dropdown[dropdown.selectedIndex].value;
// Get the column where we have WebDropDown. var insertDefault = row.get_cellByColumnKey("selection"); // Change default value only if we don't have anything selected. if (insertDefault.get_value() == "") { // Set the text and value of the insert row WebDropDown. insertDefault.set_text(dropdownValue); insertDefault.set_value(dropdownValue); }