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

Code Behind get hold of header controls via asp:button postback event.

2 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wired_Nerve
Top achievements
Rank 2
Wired_Nerve asked on 25 Oct 2013, 09:01 PM



I have a grid that is adding combo boxes to the autogenerated header rows and when 
the user clicks a button on the page I will need to determine what they selected in these combo boxes...

So I have been playing around with a foreach loop and trying to get a hock into the column's header and get the combo's.... Any suggestions?

protected void ValidateButton_Click(object sender, EventArgs e)
        {
  
// Foreach loop that will need to access the header controls and determine what a user selected in a dynamically injected //combobox...
//
}

Method that populates the Header row with combo boxes

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridHeaderItem)
            {
                GridHeaderItem item = e.Item as GridHeaderItem;
                var columnName = "Column";
                var columnCount = 0;
                foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
                {
                    RadComboBox radCombo = new RadComboBox();
                    radCombo.ClientIDMode = ClientIDMode.Static;
                    radCombo.ID = "Column" + columnCount;
                    radCombo.EmptyMessage = "Select Field";
 
                    //Need to get fields and etc,then loop and add
                    var receiveByTagsFields = GetReceiveByTagFields(Convert.ToInt32(PurchaseShipmentUid));
                    foreach (var field in receiveByTagsFields.ReceiveByTagImportFields.OrderBy(x => x.Label))
                    {
                        RadComboBoxItem CBitem = new RadComboBoxItem();
                        CBitem.ClientIDMode = ClientIDMode.AutoID;
                        CBitem.Text = field.Label;
                        CBitem.Value = field.Id.ToString();
                        radCombo.Items.Add(CBitem);
                    }
 
                    if (receiveByTagsFields.MetaFields.Count() != 0)
                    {
                        foreach (var field in receiveByTagsFields.MetaFields.OrderBy(x => x.Label))
                        {
                            RadComboBoxItem CBitem = new RadComboBoxItem();
                            CBitem.ClientIDMode = ClientIDMode.AutoID;
                            CBitem.Text = field.Label;
                            CBitem.Value = field.InventoryMetaUid.ToString();
                            radCombo.Items.Add(CBitem);
                        }
                    }
 
                    LinkButton link = new LinkButton();
                    link.ClientIDMode = ClientIDMode.AutoID;
                    link.Text = "Edit";
                    LiteralControl br = new LiteralControl("<br />");
                    if (col.ColumnType == "GridBoundColumn" || col.ColumnType == "GridNumericColumn")
                    {
                        item[col.UniqueName].Controls.Add(br);
                        item[col.UniqueName].Controls.Add(radCombo);
                    }
                    radCombo.Items.Add(new RadComboBoxItem("Do not import", "-1"));
                    columnCount++;
 
                }
            }
        }


2 Answers, 1 is accepted

Sort by
0
Wired_Nerve
Top achievements
Rank 2
answered on 28 Oct 2013, 03:27 PM
Still no luck on this... 
0
Accepted
Konstantin Dikov
Telerik team
answered on 29 Oct 2013, 08:48 AM
Hello Warren,

Could you please refer to the answer in the support ticket with ID 752140 regarding the same matter. 

For other convenience, here is the approach that could be used in order to get reference of the RadComboBox controls withing the RadGrid's header:
protected void RadButton1_Click(object sender, EventArgs e)
{
    GridItem[] headers = RadGrid1.MasterTableView.GetItems(GridItemType.Header);
    RadComboBox column0ComboBox = headers[0].FindControl("Column0") as RadComboBox;
    var selected = column0ComboBox.SelectedValue;
}

If further questions arise, I would recommend we continue our conversation in the support ticket for better tracking and consistency. 

 

Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Wired_Nerve
Top achievements
Rank 2
Answers by
Wired_Nerve
Top achievements
Rank 2
Konstantin Dikov
Telerik team
Share this question
or