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

static dropdownlist in radgrid

2 Answers 424 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tanvi
Top achievements
Rank 1
Tanvi asked on 17 Jan 2014, 10:09 AM
<telerik:RadDropDownList ID="RadDropDownList5" runat="server" AutoPostBack="true"  DataValueField="category" SelectedValue='<%#Bind("category") %>'  OnSelectedIndexChanged="category_selectedindexchaged" >
        <Items>
                                                       <telerik:DropDownListItem Text="India" Value='India' />
                                                       <telerik:DropDownListItem Text="International" Value='International' />
                                                   </Items>
       </telerik:RadDropDownList>
 
       <telerik:RadDropDownList ID="RadDropDownList6" runat="server"  >
         
       </telerik:RadDropDownList>
  
i want to fill the items in second dropdownlist based on the selection from the first static dropdownlist. how can i do it?? 

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Jan 2014, 01:14 PM
Hello,

If grid in edit mode :

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
           <MasterTableView>
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn>
                       <EditItemTemplate>
                           <telerik:RadDropDownList ID="RadDropDownList5" runat="server" AutoPostBack="true" DataValueField="category" SelectedValue='<%#Bind("Name") %>' OnSelectedIndexChanged="category_selectedindexchaged">
                               <Items>
                                   <telerik:DropDownListItem Text="India" Value='India' />
                                   <telerik:DropDownListItem Text="International" Value='International' />
                               </Items>
                           </telerik:RadDropDownList>
                           <telerik:RadDropDownList ID="RadDropDownList6" runat="server">
                           </telerik:RadDropDownList>
                       </EditItemTemplate>
                   </telerik:GridTemplateColumn>
                   <telerik:GridEditCommandColumn>
                   </telerik:GridEditCommandColumn>
               </Columns>
 
           </MasterTableView>
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable dt = new DataTable();
 
    dt.Columns.Add("ID", typeof(int));
    dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Customdate", typeof(DateTime));
 
    dt.Rows.Add(1, "India", DateTime.Now);
    dt.Rows.Add(2, "India", DateTime.Now.AddYears(-1));
    dt.Rows.Add(3, "International", DateTime.Now.AddYears(1));
 
    RadGrid1.DataSource = dt;
}
protected void category_selectedindexchaged(object sender, DropDownListEventArgs e)
{
 
    RadDropDownList RadDropDownList5 = sender as RadDropDownList;
    GridEditFormItem item = RadDropDownList5.NamingContainer as GridEditFormItem;
    RadDropDownList RadDropDownList6 = item.FindControl("RadDropDownList6") as RadDropDownList;
 
    RadDropDownList6.Items.Add(new DropDownListItem("test1", "test1"));
    RadDropDownList6.Items.Add(new DropDownListItem("test2", "test2"));
 
}

Normal Mode

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <telerik:RadDropDownList ID="RadDropDownList5" runat="server" AutoPostBack="true" DataValueField="category" SelectedValue='<%#Bind("Name") %>' OnSelectedIndexChanged="category_selectedindexchaged">
                                <Items>
                                    <telerik:DropDownListItem Text="India" Value='India' />
                                    <telerik:DropDownListItem Text="International" Value='International' />
                                </Items>
                            </telerik:RadDropDownList>
                            <telerik:RadDropDownList ID="RadDropDownList6" runat="server">
                            </telerik:RadDropDownList>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                </Columns>
 
            </MasterTableView>
        </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       DataTable dt = new DataTable();
 
       dt.Columns.Add("ID", typeof(int));
       dt.Columns.Add("Name", typeof(string));
       dt.Columns.Add("Customdate", typeof(DateTime));
 
       dt.Rows.Add(1, "India", DateTime.Now);
       dt.Rows.Add(2, "India", DateTime.Now.AddYears(-1));
       dt.Rows.Add(3, "International", DateTime.Now.AddYears(1));
 
       RadGrid1.DataSource = dt;
   }
   protected void category_selectedindexchaged(object sender, DropDownListEventArgs e)
   {
 
       RadDropDownList RadDropDownList5 = sender as RadDropDownList;
       GridDataItem item = RadDropDownList5.NamingContainer as GridDataItem;
       RadDropDownList RadDropDownList6 = item.FindControl("RadDropDownList6") as RadDropDownList;
 
       RadDropDownList6.Items.Add(new DropDownListItem("test1", "test1"));
       RadDropDownList6.Items.Add(new DropDownListItem("test2", "test2"));
 
   }


Thanks,
Jayesh Goyani
0
Tanvi
Top achievements
Rank 1
answered on 20 Jan 2014, 06:49 AM
Works perfect!!!!! thanks for the help.:)
Tags
Grid
Asked by
Tanvi
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Tanvi
Top achievements
Rank 1
Share this question
or