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

[Solved] filter dropdownlist on edit item

2 Answers 162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon Markee
Top achievements
Rank 1
Jon Markee asked on 02 Feb 2010, 02:40 AM
I have two columns in a radgrid. 

Column1 = Client
Column2 = Category

The catgory column is related to employees.  When I select edit item on the grid i need my category dropdownlist to only show categories for that client.  And if I switch the client in edit item mode i need the category drop down list to update to reflect the new categories.


Thanks,

Jon

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 02 Feb 2010, 05:07 AM
Hello,

I guess you are using DropDownColumns in your grid. If so, you can access the first dropdownlist in the editform for a column and then attach SelectedIndexChanged event as shown below.

CS:
 
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
        {  
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
            {                  
                DropDownList ddlist = (e.Item as GridEditableItem)["Client"].Controls[0] as DropDownList;                 
                ddlist.AutoPostBack = true;  
                ddlist.SelectedIndexChanged += new EventHandler(ddlist_SelectedIndexChanged);  
            }  
        }  

Then access the second dropdown in the EditForm in the SelectedIndexChanged event of the first dropdown to populate based on the selection.

CS:
 
 void ddlist_SelectedIndexChanged(object sender, EventArgs e)  
    {           
            GridEditableItem editedItem = (sender as DropDownList).NamingContainer as GridEditableItem;           
           DropDownList ddList2 = editedItem["Category"].Controls[0] as DropDownList;  
            // Set the DataSource for ddList2 with custom code here            
    }  

Also checkout the following demo which depicts similar scenario: Accessing Cells and Rows

-Shinu.
0
Jon Markee
Top achievements
Rank 1
answered on 02 Feb 2010, 04:39 PM
Thanks so much.
Tags
Grid
Asked by
Jon Markee
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jon Markee
Top achievements
Rank 1
Share this question
or