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

[Solved] Display items in radgrid based on dropdown selected item

4 Answers 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shyam k
Top achievements
Rank 1
shyam k asked on 11 Feb 2010, 03:15 PM
Hi All,
        I have a dropdown in radgrid1.  I would like to populate another radgrid based on dropdownselected item. How can i do that.
The dropdownlist is in edit mode in radgrid1.  Please help me....

Thanks in advance

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Feb 2010, 05:41 AM
Hi Shyam,

I guess you have DropDownList placed in EditItemTemplate of GridTemplateColumn like this.
aspx:
 
    <telerik:GridTemplateColumn> 
        <ItemTemplate> 
         
        </ItemTemplate> 
        <EditItemTemplate> 
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"  
                onselectedindexchanged="DropDownList1_SelectedIndexChanged"
                <asp:ListItem Text="1"></asp:ListItem> 
                <asp:ListItem Text="2"></asp:ListItem> 
            </asp:DropDownList> 
        </EditItemTemplate> 
    </telerik:GridTemplateColumn> 

You can attach 'SelectedIndexChanged' event to dropdownlist and execute the query, and set the DataSource of grid to populate it.
cs:
 
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList dropdown = (DropDownList)sender; 
        dropdown.SelectedValue.ToString(); 
        string str = dropdown.SelectedValue.ToString(); //for geting the selected item  
        string sql = "SELECT * from Categories WHERE CategoryName='" + str+"'";  
        SqlDataAdapter adapter = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);  
        DataTable dt = new DataTable();  
        adapter.Fill(dt);  
        RadGrid1.DataSource = dt;  
        RadGrid1.Rebind(); 
    } 

Regards,
Shinu.
0
shyam k
Top achievements
Rank 1
answered on 12 Feb 2010, 03:50 PM
Hey Shinu,

Thanks for the code...
0
shyam k
Top achievements
Rank 1
answered on 12 Feb 2010, 04:36 PM
HI Shinu,

Iam getting the following error when i try to use the code in runtime....

Invalidoperation exception was unhandled by the user code

object cannot be enumerated more than once.


Iam actually displaying a set of items in radgrid based on dropdown selected item.....
Is there anything that i can check to get it work...
0
Iana Tsolova
Telerik team
answered on 18 Feb 2010, 06:40 AM
Hi shyam,

Could you please provide a runnable code or share the problematic page whole code?

Best wishes,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
shyam k
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
shyam k
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or