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

WebService and SelectedValue

4 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Louis-Philippe
Top achievements
Rank 1
Louis-Philippe asked on 23 Mar 2011, 10:19 PM
Hello,
I have a page containing a radGrid, wich use a WebUserControl for edition. Inside the WebUserControl I have a bunch of radComboBox, some of them are using WebService for performance.

I notice that you can't set SelectedValue unless the user previously open the comboBox and at the same time, loaded the items, witch kind of makes sens, you can't select a value that is not inside of the comboBox at the selection time. The part that pose a problem is that I need primary key information about the selectedItem to be able to do update/insert and the client don't want to see that inside the text of the comboBox.

So first idea was to use item's attribute, but this feature can't be access server-side when using WebService and can only be set to an item, so no luck.

I then tried to add a custom made item to the comboBox that contain what I need, witch works fine until you try to load the real items...

I then tried to customize the comboBox and override  SelectedValue to keep the value inside of a private String and return the custom string when SelectedValue is empty. That mechanism works through post back, everything seems find, until I hit the Save button. The text properties is set properly, but my custom SelectedValue String is empty. Doing some forensic works, I discover that the difference responsible for my custom SelectedValue String absence of value, is that when I press the Save button the DataItem properties of the WebUserControl is set to null, so I can't reassign my custom String.

So what is the proper way to either set SelectedValue when items haven't been loaded or keep hidden primary keys inside the comboBox that will be accessible when performing update/insert?

Thanks for the help,
Louis-Philippe

4 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 29 Mar 2011, 10:44 AM
Hello Louis-Philippe,

Have you considered using different strings for the Text and Value properties of the RadComboBox items - the text would be the visible one, while the value may be completely different string, not visible to the user. You can see an example of binding the combo items text and value properties to different fields of the datasource at the following address:
Binding to DataTable, DataSet, or DataView

Or when it comes to web services, in the following example's LoadData() code, apart from setting the Text, you can also set the Value property of the item:
ComboBox / WCF Web Service

Kind regards,
Tsvetina
the Telerik team
0
Louis-Philippe
Top achievements
Rank 1
answered on 29 Mar 2011, 06:30 PM
Hello,
 Using the value or SelectedValue was the original plan, but  as I said, SelectedValue can only be set if the item containing the value has been loaded. In service mode, item are only loaded when the user click to open the comboBox. So when the WebUserControl use for edition is loaded, place where the values are set, the items are not loaded, witch prevent the use of SelectedValue.

Any other idea?

Thanks for your help,
Louis-Philippe
0
Tsvetina
Telerik team
answered on 01 Apr 2011, 02:34 PM
Hello Louis-Philippe,

Please, correct me if I am wrong but from what I understand, you ultimate goal is to access the primary key of the data entry that you are going to edit. If this is so, what you can do is set the primary key field to be ClientDataKeyNames of the grid tableview and use the client getDataKeyValue() method of the grid dataitems.

All the best,
Tsvetina
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
Louis-Philippe
Top achievements
Rank 1
answered on 01 Apr 2011, 04:58 PM
Hello,
The goal was to access the primary key of the selected item inside of the comboBox, not of the selected row. What I end up doing, is store the value inside of the parent viewState. Little bit more works, but does the trick... I someone know a better way to do this, don't be shy...

LP
Tags
Grid
Asked by
Louis-Philippe
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Louis-Philippe
Top achievements
Rank 1
Share this question
or