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

GridDropDownColumn filtering

1 Answer 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 08 Dec 2008, 05:43 PM

Hi,

I have to change the selection in GridDropDownColumn2 and other TextBoxes when the user changes the select in GridDropDownColumn while Adding and Editing data. I am using GridEditMode.InPlace.

Ex: When the user selects Profession 'Programmer' then the 2nd GridDropDownColumn should automatically  get filtered and display 'IT Dept' Otherwise 'General', by default.

 

Appreciate your help.

 

Many thanks.

JN

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 09 Dec 2008, 05:08 AM
Hello John,

Try out the following code to populate a dropdown(ddl2) in the grid based on the selection changed on another dropdown(ddl1) by assigning a different datasource:

aspx:
 <telerik:GridDropDownColumn DataSourceID="SqlDataSource1" HeaderText="DropDownColumn" DropDownControlType="DropDownList" ListTextField="ProductName" DataField="FirstName" ListValueField="ProductName" UniqueName="ProductName" > 
         </telerik:GridDropDownColumn> 
 <telerik:GridDropDownColumn UniqueName="Category" DataSourceID="SqlDataSource1" DropDownControlType="DropDownList" >         
         </telerik:GridDropDownColumn> 

cs:
  protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    {         
       if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem=(GridEditableItem)e.Item; 
            DropDownList ddl1=(DropDownList)editItem["ProductName"].Controls[0]; 
            ddl1.AutoPostBack = true
            ddl1.SelectedIndexChanged+=new EventHandler(ddl1_SelectedIndexChanged); 
           
        }        
        
    }    
    
 
void  ddl1_SelectedIndexChanged(object sender, EventArgs e) 
    DropDownList ddl1 = (DropDownList)sender; 
    GridEditableItem editedItem = ddl1.NamingContainer as GridEditableItem; 
    DropDownList ddl2 = (DropDownList)editedItem["Category"].Controls[0]; 
    // set the datasource for the second dropdown below
    ddl2.DataSource = ""
    ddl2.DataTextField = ""

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