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

how to add dynamically combobox column in Radgrid

4 Answers 240 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sandeep
Top achievements
Rank 1
Sandeep asked on 30 Dec 2008, 01:16 PM
hi all,
I'm using Asp.net Ajax Radgrid for my application but i have one problem that how to generate combobox column dynamically in radgrid.
Can anyone suggest me how to add combobox column in radgrid dynamically so that i can populate combobox at itemcreated or itemdatabound event of radgrid.


Thanks in advance!!!

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Dec 2008, 02:03 PM
Hello Sandeep,

Please test the following snippet:
protected void Page_Load(object sender, EventArgs e) 
    GridCheckBoxColumn checkBoxColumn = new GridCheckBoxColumn(); 
    RadGrid1.MasterTableView.Columns.Add(checkBoxColumn); 
    checkBoxColumn.UniqueName = "myCheckBoxColumn"
    checkBoxColumn.HeaderText = "CheckBox Column"
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        CheckBox checkBox1 = (CheckBox)((GridDataItem)e.Item)["myCheckBoxColumn"].Controls[0]; 
        checkBox1.Checked = true
    } 

Programmatic Creation On PageLoad demo

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kris
Top achievements
Rank 1
answered on 10 Dec 2009, 11:00 PM
That is pretty slick.

How would I let the user check or uncheck the boxes at their leisure? I've tried setting the ReadOnly property of the column but it is stilled greyed out and not editable.

Thanks
0
Princy
Top achievements
Rank 2
answered on 11 Dec 2009, 05:23 AM
Hello Kris,

You can either access the checkboxes and enable it in the code behind or use TemplateColumns with checkboxes in the ItemTemplate. Here's the code to enable checkboxes for a checkboxcolumn:
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            CheckBox checkBox1 = (CheckBox)((GridDataItem)e.Item)["CheckBoxColumnUniqueName"].Controls[0]; 
            checkBox1.Enabled = true
        } 
    } 

Thanks
Princy.
0
Kris
Top achievements
Rank 1
answered on 11 Dec 2009, 02:51 PM
Nice, that works exactly how I need it to. Thanks.

Tags
Grid
Asked by
Sandeep
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Kris
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or