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

[Solved] Change GridBoundColumn to GridDropDownColumn

2 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ricardo
Top achievements
Rank 1
Ricardo asked on 09 Apr 2013, 12:35 PM
Good Morning, 

I've a column in my Grid as GridBoundColumn(it's working), I need change this column to stay as GridDropDownColumn(dont working). 
Below is my GridBoundColumn and the attempt to change, don't appears error but the column is empty.

                           
     <telerik:GridBoundColumn DataField="TM_NOME" FilterControlAltText="Filter column column"
     HeaderText="Tipo de Módulo" UniqueName="TM_NOME">
     </telerik:GridBoundColumn>

       <telerik:GridDropDownColumn HeaderText="Tipo do Módulo" DataField="TM_NOME" ListTextField="NOME"                                                ListValueField="TM_NOME" DropDownControlType="RadComboBox" DataType="System.Int32">
       </telerik:GridDropDownColumn> 

ps( I saw in a example that have a parameter to GridDropDownColumn ( DataSourceID="" ), I don't know what data I must put here because in my other Columns I don't need this field.

Thanks!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Apr 2013, 01:13 PM
Hi Ricardo,

I guess you want to bind data in the GridDropDownColumn. Please take a look into the Following code.

1.If you are Binding the RadGrid declarative, using the DataSourceID. Please specify the DataSourceID in the GridDropDownColumn as shown below

ASPX:
<telerik:GridDropDownColumn HeaderText="Tipo do Módulo"HeaderText="Tipo do Módulo" DataField="TM_NOME"     ListTextField="NOME" ListValueField="TM_NOME" DataSourceID="SqlDataSource1"DropDownControlType="RadComboBox"
    DataType="System.Int32">
</telerik:GridDropDownColumn>

OR

2.If you are binding the RadGrid in Server side.

ASPX:
<telerik:GridDropDownColumn HeaderText="Tipo do Módulo" UniqueName="DropDown1"  DropDownControlType="RadComboBox"
    DataType="System.Int32">
</telerik:GridDropDownColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        //to show the value in view mode
        GridDataItem item = (GridDataItem)e.Item;
        DataRowView row = (DataRowView)e.Item.DataItem;
        item["Dropdown1"].Text = row["TM_NOME"].ToString();        
    }
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        //to populate in edit mode
        GridEditableItem ditem = (GridEditableItem)e.Item;
        RadComboBox combo1 = (RadComboBox )ditem["Dropdown1"].Controls[0];
        combo1.DataSourceID = "DataTable1";
        combo1.DataTextField = "NOME";
        combo1.DataValueField = "TM_NOME";         
    }
}

Thanks,
Shinu.


0
Ricardo
Top achievements
Rank 1
answered on 09 Apr 2013, 06:16 PM
Thank you so much Shinu, with your code my application is working now!!!

much obliged

Rgrds,
Ricardo

Tags
Grid
Asked by
Ricardo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ricardo
Top achievements
Rank 1
Share this question
or