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

Pulling Data From A RadComboBox Within A RadGrid

1 Answer 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 13 Nov 2013, 04:45 PM
Hello,

I am developing a table that displays a RadComboBox with a few options. The user is allowed to select multiple items within the RadComboBox, so check boxes are enabled. However, I am having difficulties pulling which items have been checked for each row. I cannot find the dynamically built controls to get the checked items. Also, these RadComboBoxes are not in edit mode. They are simply displaying as normal comboboxes within a grid. How would I access the checked items for each dynamically built combo box? And how could I organize this data by row?

Thanks in advance,

Derek O.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Nov 2013, 05:55 AM
Hi Derek,

Please try the following code snippet to access the data from RadComboBox checked items on RadComboBox's SelectedIndexChanged event.

C#:
protected void Page_Init(object sender, EventArgs e)
{
    RadGrid grid = new RadGrid();
    grid.AutoGenerateColumns = false;
    grid.DataSourceID = "SqlDataSource1";
    grid.MasterTableView.DataKeyNames = new string[] { "OrderID" };
 
    GridBoundColumn boundColumn1 = new GridBoundColumn();
    grid.MasterTableView.Columns.Add(boundColumn1);
    boundColumn1.DataField = "OrderID";
    boundColumn1.UniqueName = "OrderID";
    boundColumn1.HeaderText = "OrderID";
 
    string templateColumnName = "ShipCountry";
    GridTemplateColumn templateColumn = new GridTemplateColumn();
    templateColumn.ItemTemplate = new MyTemplate();
    templateColumn.HeaderText = templateColumnName;
    grid.MasterTableView.Columns.Add(templateColumn);     
         
    grid.AllowPaging = true;
    grid.PageSize = 8;
    grid.Skin = "Outlook";
    PlaceHolder1.Controls.Add(grid);
}
 
private class MyTemplate : ITemplate
{
     
    protected RadComboBox combo;
    public MyTemplate()
    {
 
    }       
    public void InstantiateIn(System.Web.UI.Control container)
    {
        combo = new RadComboBox();
        combo.ID = "RadComboBox1";
        combo.AutoPostBack = true;
        combo.DataSourceID = "SqlDataSource2";
        combo.DataTextField = "ShipCountry";
        combo.DataValueField = "ShipCountry";
        combo.CheckBoxes = true;
        combo.EnableCheckAllItemsCheckBox = true     
        combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);
        container.Controls.Add(combo);          
    }
 
    void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox combo = (RadComboBox)sender;
        GridDataItem data = (GridDataItem)combo.NamingContainer;
        string id = data.GetDataKeyValue("OrderID").ToString();
        var sb = new StringBuilder();
        var collection = combo.CheckedItems;
        if (collection.Count != 0)
        {            
           foreach (var item in collection)
            sb.Append(item.Text + "," );// Access the checked values from sb  
        }       
    }       
}

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