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

Radgrid with Autogenerated columns

3 Answers 280 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sandeep
Top achievements
Rank 1
Sandeep asked on 17 Jan 2011, 10:45 AM
Hello,
I have one radgrid which is generated dyanamically as Autogenerated columns is True.
When grid populated at "ItemDataBound" event of Radgrid I have placed RadComboBox control in each header of the column.
Now on any outside button click event I have to check where client  selected something from RadComboBox control or Not.
If not i have to indicate client to select from RadComboBox.
Once client select item from RadComboBox control for all columns, I have to export Radgrid into excel with selected item as header for that column.

Does any one have idea how to do this??

Thanks in advance.

- Sandeep.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jan 2011, 11:43 AM
Hello Sandeep,

Here is a sample code to achieve your requirement. Make necessary modification in this code according to your requirement.

C#: (Creating RadComboBox dynamically in header row of one column)
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridHeaderItem)
       {
           GridHeaderItem headerItem = (GridHeaderItem)e.Item;
           RadComboBox combo = new RadComboBox();
           RadComboBoxItem item1=new RadComboBoxItem(" ");
           RadComboBoxItem item2=new RadComboBoxItem("first item ");
           RadComboBoxItem item3=new RadComboBoxItem("second item ");
           combo.Items.Add(item1);
           combo.Items.Add(item2);
           combo.Items.Add(item3);
           headerItem["FirstName"].Controls.Add(combo);// creating RadComboBox in header row of column 'FirstName'
           combo.ID = "FirstName";
       }
   }

In Button (placed outside of grid) click, checking any item in RadComboBox is selected or not.
protected void Button4_Click(object sender, EventArgs e)
    {
        GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0]; //accessing GridHeaderItem
        RadComboBox combo = (RadComboBox)headerItem.FindControl("FirstName");
        if (combo.SelectedValue == "")
        {
            // not selected any item in RadComboBox
        }
        else
        {
            //item selected in RadComboBox
        }
    }

Exporting the Grid with Selected text of RadComboBox as column heading.

protected void Export_Click(object sender, EventArgs e)
    {
        RadGrid1.ExportSettings.OpenInNewWindow = true;
        RadGrid1.ExportSettings.ExportOnlyData = true;
        GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0];
         RadComboBox combo = (RadComboBox)headerItem.FindControl("FirstName");
        headerItem["FirstName"].Text = combo.SelectedItem.Text;
        RadGrid1.MasterTableView.ExportToExcel();
     }


Hope this helps,
Princy.
0
Sandeep
Top achievements
Rank 1
answered on 18 Jan 2011, 12:17 PM
Hi Princy,
Thanks for Reply.

But in my RadGrid there are multiple columns and each column have one RadcomboBox.
I have to find each combobox from each columns from Radgrid on Button click and then I have to export that list into Excel with
selected Text from each column ComboBox as Header for each column.

-
Sandeep
0
Marin
Telerik team
answered on 18 Jan 2011, 04:50 PM
Hello Sandeep,

You can iterate through all the columns in the grid repeat the same routine for setting up the grid for export.
Here is a sample code snippet:

protected void Export_Click(object sender, EventArgs e)
        {
            RadGrid1.ExportSettings.OpenInNewWindow = true;
            RadGrid1.ExportSettings.ExportOnlyData = true;
            GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0];
            foreach (GridColumn col in RadGrid1.Columns)
            {
                string uniqueName = col.UniqueName;
                RadComboBox combo = (RadComboBox)headerItem.FindControl(uniqueName);
                headerItem[uniqueName].Text = combo.SelectedItem.Text;
                RadGrid1.MasterTableView.ExportToExcel();
            }
        }

Kind regards,
Marin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Sandeep
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sandeep
Top achievements
Rank 1
Marin
Telerik team
Share this question
or