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

Binding GridDropDownColumn in RadGrid

5 Answers 875 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rootvik Pancholi
Top achievements
Rank 1
Rootvik Pancholi asked on 22 Jun 2010, 11:18 AM
Hi,

I want to bind RadGrid from the serverside without using SQLDatasource binding. I want to bind 2 GridDropDownColumn in that RadGrid.

Thanks.

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Jun 2010, 11:49 AM
Hello,

You can find some useful techniques from the following documentation.
Customize/Configure GridDropDownColumn

Thanks,
Princy.
0
Rootvik Pancholi
Top achievements
Rank 1
answered on 22 Jun 2010, 12:14 PM
Hello Princy,

Thanks for the Quick reply.

I have put such code in aspx file to bind GridDropDownColumn in RadGrid.
 <telerikUI:RadGrid ID="ContactGrid" runat="server" Skin="Vista" AutoGenerateColumns="false" 
                        Visible="true" PageSize="2" AllowPaging="true" OnNeedDataSource="ContactGridData" 
                        AllowSorting="true" OnItemDataBound="ContactGrid_ItemDataBound1" OnDataBound="ContactGrid_DataBound">  
                        <PagerStyle Mode="NextPrevAndNumeric" />  
                        <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" HorizontalAlign="NotSet" 
                            AutoGenerateColumns="false" EditMode="InPlace">  
                            <Columns>  
                                <telerikUI:GridDropDownColumn HeaderText="DeviceType" ListDataMember="ID" ListTextField="DeviceType" 
                                    ListValueField="ID" UniqueName="DDLDeviceType" DataField="GridDeviceType">  
                                </telerikUI:GridDropDownColumn>  
 </Columns>  
                        </MasterTableView>  
                    </telerikUI:RadGrid> 

In the .cs File i have applied this code at the updation time.

 protected void ContactGrid_ItemDataBound1(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            GridEditableItem editedItem = e.Item as GridEditableItem;  
            GridEditManager editMan = editedItem.EditManager;  
 
            GridDropDownListColumnEditor DDLDevice = editMan.GetColumnEditor("DDLDeviceType"as GridDropDownListColumnEditor;  
            DDLDevice.DataSource = DeviceConfigurationsDB.GetDeviceConfigurationsByGPNSUserID(156);  
            DDLDevice.DataTextField = "ID";  
            DDLDevice.DataValueField = "ID";  
            DDLDevice.DataBind();  
        }  
          
    } 

This is Showing me values in the dropdown on the click of Edit button.

But i am not getting any display in the RadGrid.

 

Thanks.

0
Veli
Telerik team
answered on 24 Jun 2010, 03:55 PM
Hello Rootvik,

The GridDropDownColumn does not support manual databinding. Particualrly, as you noted, you can bind the combo, but you cannot bind the rest of the cells in view mode. Only declarative data sources and DataSets are supported by the GridDropDownColumn. It would probably be easier for you to just use a GridTemplateColumn with a RadComboBox in the EditItemTemplate.

All the best,
Veli
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
Carlos Contreras
Top achievements
Rank 1
answered on 12 Jul 2010, 07:36 PM

Hi Veli!

I want to do something very similar like this post's author.

I follow your suggestion of using a GridTemplateColumn with a RadComboBox in the EditItemTemplate, but in order to show a value in the View Mode (or ItemTemplate) I used a Label in the ItemTemplate, but I'm getting the following error message: "Unable to cast object of Type 'System.Web.UI.LiteralControl' to 'Telerik.Web.UI.RadComboBox'" when I try to edit a record.

I understand that type of casting isn't possible because a Label has a simple text propery, while a ComboBox has a collection of items.

Do you got any idea of how can I solve this?


Thanks!
0
Veli
Telerik team
answered on 13 Jul 2010, 08:58 AM
Hi Carlos,

You are trying to cast a Label to a RadComboBox, because you assume your item has RadComboBox inside. This is only true for items in edit mode. That is why you need to check whether the current item is in edit mode. If true, try to find the combo, if not, find the Label.

Best wishes,
Veli
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
Tags
Grid
Asked by
Rootvik Pancholi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rootvik Pancholi
Top achievements
Rank 1
Veli
Telerik team
Carlos Contreras
Top achievements
Rank 1
Share this question
or