Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
495
DropDownProvider default value
posted

Hello - 

I've got a drop down provider in a web grid.  I have populated the values of the drop down in the code behind on page_load so 0 = "", 1="red", 2="blue", 3="green".

 I am adding a new row to the grid via JavaScript which works fine, but the display in the cell with the drop down is 0 - no matter what I put in there - whether the default value is 0, "" or null.  I can select a value after that, and the list is correct and it retains the new value, but was I really need is that drop down to display the correct text associated with the value its set to.  

What am I missing?

thanks,

Jeff

Parents
No Data
Reply
  • 49378
    posted

    Hi Jeff,

    Thank you for posting in the community.

    As far as I can understand, when setting a value for your new row cell through javascript, you wish that value to be transposed to the corresponding text (associated with that value) in the DropDownProvider. Using your example, setting 0 for the respective cell should result in an empty string in the newly added row.

    This can be achieved by manually accessing the DropDownProvider and iterating through its items to find the one with the required value. Here is a sample implementation for such a scenario:

    Code Snippet
    1. function buttonHandler() {
    2.     var grid = ig_controls.WebDataGrid1;
    3.     var provider = ig_controls.WebDataGrid1_ctl00;
    4.  
    5.     var valueToDisplay = 0;
    6.  
    7.     //loop through the provider's items to find the one with value 0
    8.     for (i = 0; i < provider.get_items().get_length(); i++) {
    9.         if (valueToDisplay == provider.get_items().getItem(i).get_value()) {
    10.             var itemText = provider.get_items().getItem(i).get_text();
    11.         }
    12.     }
    13.  
    14.     var newRow = new Array(0, itemText);
    15.  
    16.  
    17.     grid.get_rows().add(newRow);
    18. }

    Please let me know if this helps.

Children