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

Dropdown Selected Value In Grid Item Created Event

2 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sushanth
Top achievements
Rank 1
Sushanth asked on 21 Aug 2012, 10:01 AM
Hello,

I have multiple radGrids on a page and an additional dropdown control outside the RadGrid. I want to display the grids based on the selection in the dropdown. Now in the Grid's item created event, I need to get the dropdown's selected value which I am unable to get as the Item created event is fired before the dropdown's selectedindex changed event. Any help on this is greatly appreciated.

- Sushanth.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Aug 2012, 10:31 AM
Hi,

One suggestion is to call a rebind method of the RadGrid in the SelectedIndexChanged event of the DropDownList and there by get the selected value in the ItemCreated/ItemDataBound event.

C#:
string value = string.Empty;
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
     if (e.Item is GridDataItem)
    {
        if (value != "")
        {
            //your code
        }
    }  
}
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        if (value != "")
        {
            //your code
        }
    }
}
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddl = (DropDownList)sender;
    value = ddl.SelectedItem.Text;
    RadGrid1.Rebind();
}

Thanks,
Princy.
0
Sushanth
Top achievements
Rank 1
answered on 21 Aug 2012, 11:29 AM
Hello Princy,

Thanks for your immediate response.
we still are facing the issue as this is a little different scenario we have which we are confused with. The following is what we have:

1) RadComboBox contains table names with a default selection on page load.
2) Grid loads the table for the table name selected by default.
3) We have a javascript event being assigned to filter textboxes through item created event as follows:
 if (e.Item is GridFilteringItem)
            {
                GridFilteringItem filterConstraint = e.Item as GridFilteringItem;
                foreach (GridColumn column in RadGrid1.Columns)
                {
                    if ((filterConstraint[column.UniqueName].Controls.Count > 0) &&
                        (filterConstraint[column.UniqueName].Controls[0].ID == "FilterTextBox_" + column.UniqueName))
                    {
                        TextBox filtertxtbox = filterConstraint[column.UniqueName].Controls[0] as TextBox;
                        filtertxtbox.Attributes.Add("onkeyup", "SettingwidthToControl(this);");
                    }
                }
            }
4) We now are trying to invoke the same event instead of individual item created events to multiple grids on the page. So we need to change the condition in foreach with different grid names.
5) I am trying to get the table name and there by get the grid name from the ComboBox selected index changed event.
From your suggestion I have tried the following:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {

            RadGrid tempradgrid = new RadGrid();
            if (dditem != "")
            {
                tempradgrid = GetRadgrid(dditem);
            }           

            if (e.Item is GridFilteringItem)
            {
                GridFilteringItem filterConstraint = e.Item as GridFilteringItem;

                foreach (GridColumn column in tempradgrid.Columns)
                {
                    if ((filterConstraint[column.UniqueName].Controls.Count > 0) &&
                        (filterConstraint[column.UniqueName].Controls[0].ID == "FilterTextBox_" + column.UniqueName))
                    {
                        TextBox filtertxtbox = filterConstraint[column.UniqueName].Controls[0] as TextBox;
                        filtertxtbox.Attributes.Add("onkeyup", "SettingwidthToControl(this);");
                    }
                }
            }
}

where dditem is the ComboBox item getting its value from the ComboBox selected changed event.

Can you please suggest us in a more detailed way.
Thanks in advance.

- Sushanth.


Tags
Grid
Asked by
Sushanth
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sushanth
Top achievements
Rank 1
Share this question
or