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
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:
Please let me know if this helps.
Hi Petar,
I think it has to do with the underlying data type I am binding the column to. When I had the datatype as an integer in a SQL DB, and setup the selections in the drop down list as ("",0), ("Red",1),("Blue",2),("Green",3) it would display the numeric value instead of the corresponding display text.
I changed the column to an nvarchar, and I only initialize the drop downs with the text, not the text value pair, and now its displaying the string label.
that will work for now.
Thank you for your reply.
Glad that you found a solution. Please feel free to contact me if I can be of further assistance.
Hi
Is there actually a better solution to this or is this a bug? We have a dropdown provider on our grid which has a list of values from the database where the ValueField column is a Guid and the TextField is a description.
The problem shown below occurs when you click on a cell if the value of the TextField is an empty string. For some reason it shows the data from the ValueField instead???
If we modify the data source to return a space (' ') instead of an empty string this does not occur. Is there a way to stop this happening with the empty string? Is there another way to handle this?
Thanks.