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

Popupating a RadCombo box inside a RadGrid

3 Answers 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
A2H
Top achievements
Rank 1
A2H asked on 21 Feb 2011, 06:40 AM
Hi All,
I have a requirement.

I want to populate a radcombobox inside a radgrid on initial pageload.
I dont want the Combobox to populate on EditEvent.
I have put the Combox in GridTemplates ItemTemplate columns


How can I acheive this.

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 21 Feb 2011, 09:21 AM
Hello,

Please try the following approach to populate the RadCombobox in Itemtemplate.
ASPX:
<telerik:GridTemplateColumn>
    <ItemTemplate>
        <telerik:RadComboBox runat="server" ID="RadComboBox1">
        </telerik:RadComboBox>
    </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
       if (e.Item is GridDataItem)
        {
            GridDataItem Item = (GridDataItem)e.Item;
            RadComboBox combo = (RadComboBox)Item.FindControl("RadComboBox1");
            combo.DataSource = //populate RadComboBox
            .  .   .   .   .
        }
   }

Thanks,
Princy.
0
A2H
Top achievements
Rank 1
answered on 21 Feb 2011, 10:05 AM
Hi Princy,

Thanks a ton issue solved :):):)

I was using other keywords except GridDataItem and always it was throwing error

one more question:

how to persist the value selected in combobox

Thanks,
A2H
0
Princy
Top achievements
Rank 2
answered on 22 Feb 2011, 06:22 AM
Hello,

If you want SelectedValue of RadComboBox is based on grid row, try the following approach. Or you can simply select the value in RadComboBox using 'combo.SelectedValue' property.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
        if (e.Item is GridDataItem)
       {
           GridDataItem Item = (GridDataItem)e.Item;
           RadComboBox combo = (RadComboBox)Item.FindControl("RadComboBox1");
           combo.DataSource = ;//populate RadComboBox
           combo.DataTextField = "FirstName";
           combo.DataValueField = "FirstName";
           DataRowView rowView = (DataRowView)Item.DataItem;
           combo.SelectedValue = rowView["FirstName"].ToString();
       }
   }

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