I have a WebGrid where there is a first column of Type DropDownList , and another DropDownList column .
The first column has the datasource settings in the Page_Load (for all the rows the first column has the same values as ValueList), instead the secound column should have a ValueList that depends from the currently selected values in the first column.
This is the aspx part for the columns:
And:
<ClientSideEvents CellChangeHandler="grdStentsLAD_CellChangeHandler"/>
The javascript code:
function grdStentsLAD_CellChangeHandler(gridId, newActiveCellId) { if (newActiveCellId == "") { // when click on Add New button return; } var objGrid = igtbl_getGridById(gridId); var objCell = igtbl_getCellById(newActiveCellId); var objRow = objCell.getRow(); if (objGrid.Rows.getRow(objRow.getIndex()).getCellFromKey('StentDiam').Id == newActiveCellId) { var strType = objGrid.Rows.getRow(objRow.getIndex()).getCellFromKey('Type').getValue(); PageMethods.GetFilteredDiams(strType, newActiveCellId, grdStentsLAD_CellChangeHandler_Callback, grdStents_CellChangeHandler_ErrorCallback, gridId); }}
In my js code i'm calling a Ajax page method (GetFilteredDiams), that returns an array of strings , so the callback code is
function grdStentsLAD_CellChangeHandler_Callback(result, response, context) { var strCellId = result[0]; // response contains gridId passed as context var objGrid = igtbl_getGridById(response); var objCell = igtbl_getCellById(strCellId); var objRow = objCell.getRow(); var objColumnDiam = igtbl_getColumnById(strCellId); var vlist = new Array(result.length - 1); for (i = 1; i < result.length; i++) { vlist[i] = new Array(result[i], result[i]); } objColumnDiam.ValueList = vlist;}
The first array element is used to save the HTMLid of the original cell (CellId).
Following the code with debugger i can see that all is working as expected, the returned array from the page method contains the right values that i'm expected to see for the clicked StentDiam cell, but there is a problem: opening the list with the cell dropdown button doesn't immediately show the right values (i can see the values of another row previously clicked, for example) even if in js code the values was correct: i must click on another cell (for example the Type) then reclicking the StentDiam cell the ValueList is now correct (i hope that my explanation is clear...)
Why this problem? could be that with the service pack , downloadable only if you have a regular license, is resolved? or there is some code to add?
There is even the fact that the ValueList for StentDiam should change changing the selected Type, but for now i'm interested to resolve this issue.
I'm using Visual Studio 2008 with the latest Infragistics trial :i'm evaluating just for the problem of dinamically filtered DropDown that with a GridView ,working with postbacks, is very slow.
Just to complete one point :
When you assign the values to the dropdown, check before if the _valueList is not null and begin the generateValueList function by
_valueList = null;
Else there are some strange behavior on the other editable column of your grid.
Hello,
I faced the same issue and it seems I found a solution to populate the dropdown dynamically :
First of all, you need to create a javascript function containing the code that retrieves the data to put in your dropdown.
On my side, I created the generateValueList as you can see :
function generateValueList(gridName, cellId) { _gridName = gridName; _cellId = cellId; var col = igtbl_getColumnById(_cellId); if (col.Key != "Value") return; ..... some code to assign my parameters.... PageMethods.fillValueList(_reference, releaseCode,successCallback,failCallback); }
Notice I put the content of my parameter in global variable ( _XXXXX name) as I will use them again after.
The failCallback function is not important to describe.
The successCallBack function make some treatment to create a two dimensions table for the dropdown, and put it in a global variable. I still not assign the value in the dropdown.
function successCallback(result, userContext, methodName) { .... treatment to create the valueListArray table..... _valueList = valueListArray; }
Now, how to call all of that...
First of all, in the BeforeEnterEditModeHandler, I just assign the variable _valueList to the dropdown.
function dgrdProduct_BeforeEnterEditModeHandler(gridName, cellId) { var col = igtbl_getColumnById(_cellId); col.ValueList = _valueList; }
The call to the generateValueList function is done before to click, in the MouseOverHandler :
function dgrdProduct_MouseOverHandler(gridName, cellId){ generateValueList(gridName, cellId); }
Then, each time your mouse is on the grid, on the good column, your list of value is generated, and before you enter in edit mode, the list is assign to the drop down. And for what I see now, it works.
Good luck
I have resolved the issue coding by hand the filtered values in code:
function grdStentsLAD_CellChangeHandler(gridId, newActiveCellId) { if (newActiveCellId == "") { // when click on Add New button return; } var objGrid = igtbl_getGridById(gridId); var objCell = igtbl_getCellById(newActiveCellId); var objRow = objCell.getRow(); if (objGrid.Rows.getRow(objRow.getIndex()).getCellFromKey('StentDiam').Id == newActiveCellId) { var strType = objGrid.Rows.getRow(objRow.getIndex()).getCellFromKey('Type').getValue(); var objColumnDiam = igtbl_getColumnById(newActiveCellId); var vlist; switch (strType) { case "CYPHER": vlist = new Array(5); vlist[0] = new Array("2.5", "2.5"); vlist[1] = new Array("2.9", "2.9"); vlist[2] = new Array("3.9", "3.9"); vlist[3] = new Array("4.9", "4.9"); vlist[4] = new Array("5.9", "5.9"); break; case "ENDEAVOR": vlist = new Array(4); vlist[0] = new Array("2.1", "2.1"); vlist[1] = new Array("2.5", "2.5"); vlist[2] = new Array("3.1", "3.1"); vlist[3] = new Array("4.5", "4.5"); break; } objColumnDiam.ValueList = vlist; // Page Method no more used .... // PageMethods.GetFilteredDiams(strType, newActiveCellId, grdStentsLAD_CellChangeHandler_Callback, grdStents_CellChangeHandler_ErrorCallback, gridId); } }
That is the page method with relative callback is no more used and all works as expected : it seems that the interruption in the pagelife cycle caused by page method (with the return to a callback) is the problem.
This solution has the drawback that the users can't manage the values in the web app, but for the moment is acceptable.
Rumen Stankov"]Hello,Most probably this is a page lifecycle thing, e.g. setting the values in Page_Load is too late (or in some rare cases, too early) in the page lifecycle to take effect when it is intended to.My suggestion is to move the ValueList initialization code to1) Page.OnInit event2) Page.OnPreRender eventand see how it affects the page. Depending on the databinding you are using (e.g. are you using InitializeDataSource event, or are you binding the grid directly (and if so, in which event of the page), or are you using declarative DataSource thru the DataSourceID of the page), Page_Load might not be the perfect place to do that.
Most probably this is a page lifecycle thing, e.g. setting the values in Page_Load is too late (or in some rare cases, too early) in the page lifecycle to take effect when it is intended to.
My suggestion is to move the ValueList initialization code to
1) Page.OnInit event
2) Page.OnPreRender event
and see how it affects the page. Depending on the databinding you are using (e.g. are you using InitializeDataSource event, or are you binding the grid directly (and if so, in which event of the page), or are you using declarative DataSource thru the DataSourceID of the page), Page_Load might not be the perfect place to do that.
But i'm speaking of javascript code that changes a cell when i click on the cell, not of initial rendering