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?
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: break; } } } function ClearReadingCells(row) { row.get_cellByColumnKey( "PNT_UOM").set_value(null); row.get_cellByColumnKey( "ALRT_UPPER").set_value(null); row.get_cellByColumnKey( "ALRT_LOWER").set_value(null); row.get_cellByColumnKey( "WRN_UPPER").set_value(null); row.get_cellByColumnKey( "WRN_LOWER").set_value(null); row.get_cellByColumnKey( "WRN_TEXT").set_value(null); }
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(
pointTypeCell.set_value(
'M','Measurement'); }
}
if (pointTypeCell.get_value() != "M") { ClearReadingCells(row);
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(
eventArgs.set_cancel(
true);
break;
default:
break; } } }
ClearReadingCells(row) { row.get_cellByColumnKey(
row.get_cellByColumnKey(
"PNT_UOM").set_value(null); row.get_cellByColumnKey(
"ALRT_UPPER").set_value(null); row.get_cellByColumnKey(
"ALRT_LOWER").set_value(null); row.get_cellByColumnKey(
"WRN_UPPER").set_value(null); row.get_cellByColumnKey(
"WRN_LOWER").set_value(null); row.get_cellByColumnKey(
"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); }
Hello AriV,
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.
Let me know if you have any questions with this matter. Thank you.
I need to do the same thing. When they enter edit mode on any cell I want the DropDownProvider in the first cell set to thefirst value in the list. If I could find the dropdown control that would be easy, but the DropDownProvider does not have a ClientID property. I tried setting the value and text properties of the cell, but that doesn't actually set the ddl value and in any case I can't figure out how to set them differently. Wehn I set the text property it also changed the value, and vice versa. Have you managed to figure this out yet?
function wdgEQMonPointsList_EnteringRowAddingEditMode(sender, eventArgs) { var grid = $find("<%= wdgEQMonPointsList.ClientID %>"); var activeCell = grid.get_behaviors().get_activation().get_activeCell(); var newRow = grid.get_behaviors().get_editingCore().get_behaviors().get_rowAdding().get_row() var pointTypeCell = newRow.get_cell(1); if (!pointTypeCell.get_value()) {// newRow.get_cell(1).set_text("Measurement");// newRow.get_cell(1).set_value("M"); var ddl = $find("wdgEQMonPointsList_DD_PointType"); ddl.get_items().getItem(0).select() } else { alert(pointType); if (pointType != "M") { ClearReadingCells(newRow); switch (activeCell.get_column().get_key()) { case "PNT_UOM": case "ALRT_UPPER": case "ALRT_LOWER": case "WRN_UPPER": case "WRN_LOWER": eventArgs.set_cancel(true); break; default: break; } } } }
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).