This is a migrated thread and some comments may be shown as answers.

ComboBox works inside a Grid, but not outside....

4 Answers 66 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kai-Tobias
Top achievements
Rank 1
Kai-Tobias asked on 14 Dec 2010, 06:52 PM
Hi,

I couldn't find a solution to my problem, so I hope somebody can tell me where I went wrong..

I want to use a ComboBox as an element to choose a person's salutation like "Mr.", "Mrs.", etc. Some standard phrases just like "Mr." and "Mrs." shall be available in the DropDownList and if a salutation like "Prof. Dr. Dr. med. rer. nat." or something appears, it can be typed in.

I created that standard list and server-bound (.bindTo) it to the ComboBox. The salutations I choose or type in are perfectly saved as a string in my database. So basically, everythign works fine. BUT, it seems to depend where I use the ComboBox...

One time the ComboBox is used in a Grid as an EditorTemplate and everything works perfectly fine!
Then, I need to use it for the exact same functionality in a form on a view where personal data like the persons name etc.. shall be editable. The binding to the list of salutations works fine and if I type something in or choose one of the available options, they are submitted and saved correctly.
But in contrast to the ComboBox used in the Grid, the one used in the view does not show the viewmodel's property value.

I couldn't find a difference in the code, but mybe I just missed something..
Does anyone know what I am doing wrong?
I attached a small test project, which shows my problem..

Thanks in advance..!

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 15 Dec 2010, 02:35 PM
Hi Kai-Tobias,

The problem is caused by inconsistency between sals  SelectList and values saved in the DB. In other words Salutation in DB is saved as "Mr.    " and in sals list first item is "Mr.", which are not same. Hence the combobox will never be able to select correct item. You can fix this like so:

public CustomersViewModel CreateCustomersViewModelForDetailsPage(TabCustomers customer)
{
    CustomersViewModel model = new CustomersViewModel();
    model.CustomerID = customer.CustomerID;
    model.Name = customer.Name;
    model.Salutation = customer.Salutation.Trim();
 
    return model;
}

All the best,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kai-Tobias
Top achievements
Rank 1
answered on 15 Dec 2010, 04:39 PM
Hi Georgi,

thank you for the quick reply!
Thanks to the changes you suggested, the salutations which exist in the "sals" List are now shown by the ComboBox on the details page.

Now if I save a salutation different from the ones in "sals", like "Prof. Dr.", then "Prof. Dr." becomes the value of the property in the database, but the input field of the ComboBox does not display "Prof. Dr." when the page is loaded again, it is just empty.
Is it possible to have the value of the property shown by the input field of the ComboBox, even if it is no item of the ComboBox's dataSource?

For now I use a workaround, in which I load the input field using JavaScript and a hidden TextBoxFor, but I am sure there is a "correct" way to do this, isn't it?

Thank you for your effort!
Kai
0
Accepted
Georgi Krustev
Telerik team
answered on 20 Dec 2010, 10:37 AM
Hello Kai-Tobias,

 The workaround which you are using now is the only available for the time being.

The limitation that you hit is currently fixed and will be available in the next official release of Telerik Components for ASP.NET MVC.

All the best,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kai-Tobias
Top achievements
Rank 1
answered on 03 Jan 2011, 09:17 AM
Hi Georgi,

happy new year first of all and thank you for your reply.

Now I know, so I am looking forward for the next release!

best regards,
Kai
Tags
ComboBox
Asked by
Kai-Tobias
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Kai-Tobias
Top achievements
Rank 1
Share this question
or