Wednesday, May 07, 2008

Telerik RadComboBox in a RadGrid

Ok, this post is only a half post, as for now I will leave out a lot of details. I use Telerik's control suite for ASP.Net (www.telerik.com) at work. I spent about four hours yesterday trying to get a RadComboBox's selected value to bind to a column in the Grid's dataset when in edit mode (so I could get two way databinding on the grid so it will handle the update/delete/insert automatically as long as you setup the appropriate procs and params in your SQL datasource).

Without including all the details I couldn't get things to work until I bound the RadComboBox to a column that initially had the value of ''in the dataset . Then, in the item data bound event I set the value the RadComboBox to the value it should be.

So in my stored proc I had to return two columns like this, mycolumn (which I set in the select to ''), and then mycolumn_real_value which in the stored proc is the value that should be the value for mycolmn. The RadComboBox's selectedvalue is bound to mycolumn like selectedvalue='<%# Bind("mycolumn") %>'. Then in the item data bound event for the Grid I cast the e.Item as a GridItem, then do a findcontrol to find the RadComboBox, then set the text of that RadComboBox to the value of mycolumn_real_value. Also you can't give the RadComboBox a DataSourceID. I ended up building a function that pulls a new DataView out of a DataSource, then loops through that view's rows and add's new items to the RadComboBox.

I'm sure there is another way, but I couldn't get anything else to work, including the downloaded Telerik examples.

I'll post actual code for this at one point, and to 99% of you who read this it will sound like a bunch of nonsense(like most of my post), but to those of you like me who have been pulling their hair out to get two way databinding to work on a RadComboBox in a RadGrid the above will put you on the right path.

4 comments:

Anonymous said...

I use the new ASP.NET AJAX version of RadGrid and RadComboBox and binding directly the selected value using GridDropDownColumn or template column with combobox editor worked for me as in the demos:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Controls/Examples/Integration/GridEditors/DefaultCS.aspx?product=grid

http://www.telerik.com/support/kb/article/b454K-gmk-b454T-cbb-b454c-cbb.aspx

Give them a try or post about your case in the forums on the Telerik site and you may get even closer to what you are after. Their community seems quite responsive and helpful from my point of view.

James

Anonymous said...

Ready to bet everything that James works for Telerik. They have people searching the net for any negative comment about their half-working, full of bugs components.
The support just directs you to their samples too, as James did.
I don't mind when open source components like the ajax control toolkit has bugs, because they encourage people to solve them AND IT'S FREE. When you pay, you expect bug-free heaven.

infocyde said...

Yeah, James probably works for Telerik. So what. Over all, Telerik has enabled me to do things at work in a very short amount of time that otherwise would have taken me months to develop on my own, if I even could develop a control suite that comes close. There tech support is decent. I've gotten a few what I would call lazy answers from support techs, but, just like in this case, I didn't provide a lot of detail, so I can't blame them for their response. Sometimes I get frustrated with the controls, both because I don't know what I'm doing all the time or I'm doing something that is normally out of scope, but overall I feel my company made a really good investment by purchasing telerik's control suite. I look forward to more jQuery and Prototype plugins that can do a lot of what currently telerik can do so I can use the open source equivalents on my side projects, but if anyone has the cash and needs the functionality I would recommend Telerik's controls suite full heartedly.

Suresh Deevi said...

I just added <telerik:RadComboBox SelectedValue='<%# Bind("Period")%>'< and it worked well