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

[Solved] Radcombo in one column in radgrid

6 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shweta
Top achievements
Rank 1
Shweta asked on 07 Jun 2011, 11:29 AM
Hi, 

I have a radgrid which i populate runtime using a dataset.
After that i need to add a radcombobox to every cell in one column of the radgrid.

For eg in the code below, for all cells in the "SECOND" column, i need a dropdown.
Can I get some help? Sample code will be very helpful

Dim tbl As DataTable = New DataTable
       tbl.Columns.Add("FIRST")
       tbl.Columns.Add("SECOND")
       Dim i As Integer
       For i = 0 To 4
           Dim row As DataRow = tbl.NewRow
           row.Item(0) = "ONE"
           row.Item(1) = "TWO"
           tbl.Rows.Add(row)
       Next
       RadGrid1.DataSource = tbl
       RadGrid1.Rebind()

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Jun 2011, 12:52 PM
Hello Shwetha,

Try the following code in ItemCreated event to add RadComboBox dynamically. Hope this helps you.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
        GridDataItem item = (GridDataItem)e.Item;
    TableCell cell=item["ColumnUniqueName"];
        RadComboBox combo = new RadComboBox();
     combo.ID="combo";
     combo.DataSource=//set your datasource here
    cell.Controls.Add(combo);
     }
 }

Thanks,
Princy.
0
Shweta
Top achievements
Rank 1
answered on 07 Jun 2011, 01:49 PM
Thanks for the quick response Princy.
I tried your code, but it stops at

TableCell cell=item["ColumnUniqueName"];

It says
"Failed accessing GridColumn by index. Please verify that you have specified the structure of RadGrid correctly."
Sorry, I guess I am missing something very basic, since i am new to Asp.net as well as RadControls.

Thanks again,
Shweta
0
Shweta
Top achievements
Rank 1
answered on 09 Jun 2011, 06:28 AM
Thanks a ton.
Worked fine, only instead of itemcreated, i did it on itemdatabound. :)
One more question.
I want to add items (NOT using a datasource, but through code) to the combos added to this column.
Could you please help me?

Regards,
Shweta
0
Shweta
Top achievements
Rank 1
answered on 09 Jun 2011, 09:48 AM
Hi,

Got this too.
Another question about Radgrid, in the same context.
Before adding radcombos to all cells in one column, i want to get the value already existing in that cell.
How can i get it? in the itemdatatbound event itself? or in which event can i capture it?

Thanks,
Shweta
0
Mona
Top achievements
Rank 1
answered on 25 May 2013, 12:57 AM
Hi,
How would you get the parent cell of RadComboBox in a OnClientDropDownClosedHandler?

This is is an ItemTemplate in a RadGrid
<telerik:RadComboBox ID="TerritoryManagerRadComboBox" runat="server" onclientdropdownclosed="OnClientDropDownClosedHandler">

 


function

 

 

OnClientDropDownClosedHandler(sender, eventArgs) {
  // here I want to get the cell object

 

 }

I need the cell object so that I change the style of the whole cell the RadComboBox is in. Or is there another way to do this?
0
Princy
Top achievements
Rank 2
answered on 28 May 2013, 06:01 AM
Hi,

You can attach the OnClientDropDownClosed event from ItemCreated event ans can pass the Parent cell's ClientID as follows.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if(e.Item is GridDataItem)
    {
        GridDataItem ditem = (GridDataItem)e.Item;
        RadComboBox com = (RadComboBox)ditem.FindControl("TerritoryManagerRadComboBox");     
        com.OnClientDropDownClosed = "function (button,args){OnClientDropDownClosedHandler('" + com.Parent.ClientID + "');}";
    }
}

Javascript:
<script type="text/javascript">
    function OnClientDropDownClosedHandler(id) {    
        var parentcell = document.getElementById(id); //you can access the parent cell here     
    }
</script>

Thanks,
Princy.
Tags
Grid
Asked by
Shweta
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shweta
Top achievements
Rank 1
Mona
Top achievements
Rank 1
Share this question
or