Hello,
I am using IG version 17.2 with VS 2012. I have a databound WebDropDown in MultiSelect mode. What I am trying to accomplish is: Allow the user to enter a new item into the DropDown control and SQL database table, select that item, then display the new item in the DropDown text. I will deeply appreciate any help on how I can accomplish this or if it's possible.
Please find attached my sample solution and database samples attached.
Thank you,
Alex,
You are correct. The newly entered item is not to replace the "Other" item in the database, The newly entered item is added to the database using the PageMethod. The "Other" item on the client is unselected and replaced with the newly entered item and displayed on the client. The bolded code lines below is where the scenario is failing. It not producing an error but just not performing as I intend..
function cboFTEName_DropDownClosed(sender, eventArgs) { ///<summary> /// ///</summary> ///<param name="sender" type="Infragistics.Web.UI.WebDropDown"></param> ///<param name="eventArgs" type="Infragistics.Web.UI.DropDownContainerEventArgs"></param>
var FTEcombo = sender; var Items = sender.get_selectedItems(); for (i = 0; i < Items.length; i++) { if (Items[i].get_text() == "Other") { var newFTEName = prompt("Enter Name of Other FTE:", ""); if (newFTEName !== null) { if (confirm("You are about to add a new FTE Name to the database.\n Are you sure you wish to continue?")) { //Add the newly entered FTE Name to the database table. PageMethods.AddNewFTEName(newFTEName, OnSucess, OnFailure); } function OnSucess(response, UserContext, methodName) { //Add the new FTE Name to the client dropdown and select it. if (response.length > 0) { var idpos = response.indexOf("|"); var newid = response.substring(0, idpos); var item = FTEcombo.get_items().createItem(); item.set_text(newFTEName); item.set_value(newid); FTEcombo.get_items().add(item); var itemIndex = item.get_index(); FTEcombo.selectItemByIndex(itemIndex); var FTEItems = FTEcombo.get_selectedItems(); //Unselect the "Other" Selection and replace with the new entry on client for (j = 0; j < FTEItems.length; j++) { if (FTEItems[j].get_text() == "Other") { FTEItems[j].unselect(); var strValue = FTEcombo.get_currentValue(); var newValue = strValue.replace("Other", newFTEName); FTEcombo.set_currentValue(newValue); } } } } function OnFailure(error) { alert(error.get_message()); } } } }}// --></script>
Thank you for your response!
Can you please clear out an additional question - you have the "Other" item defined in your database and you do not want to replace this item in the database with the custom item but you want to replace it on the client only. And the custom item, except for replacing the "Other" item on the client, should also be added to the database. Is that correct?
Hello Alex and thank you for taking the time to look into this. The scenario fails when when the attempt select and display the newly added item. The PageMethod does add the item to the database table as expected. The help link you provided is similar to what I need. However, I require the new entry to be added only when the "Other" value is checked, then replace the value of "Other" with the newly entered value.
Hello!
Thank you for using Infragistics ASP.NET!
Thank you for the provided sample – I had troubles running it but the code helped me to understand your scenario.
Can you please tell me where does your scenario fail? Is the new item not added to your database? Or the item is not added to the dropdown control when executing the “OnSucess” function?
I think this help topic may be of help as the scenario looks similar to the one that you need - https://ko.infragistics.com/help/aspnet/webdropdown-custom-values-and-persistence
Can you please look at it and let me know if this is resolving your issue?
Thank you once more for contacting the Infragistics support!
I am looking forward to your response!
Best regards, Alexander Marinov
Apologies.. Link to sample project blow.
https://drive.google.com/open?id=1UO88ybpsjxHMo9rlvvMDvoIa1HGdgh9X