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

[Solved] Want to access dropdownlist and give the send the selected value to other dropdownlist inside a radgrid.

1 Answer 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shahid Aleem
Top achievements
Rank 1
shahid Aleem asked on 04 Feb 2010, 07:32 PM
Hello,

I have a radgridview... inside that i have two dropdownlistsin the edititemtemplate. When i want to edit a row. the selected valeu should be the one which was there as a label.
And if i change any value from first dropdownlist. iwant to send its selected value to another dropdownlist...
please tell me how to do this.... reply soon.
<telerik:GridTemplateColumn> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label1" runat="server" Text='<%#Bind("Equipment") %>'></asp:Label> 
                                </ItemTemplate> 
                                <EditItemTemplate> 
                                    <asp:DropDownList DataSourceID="SqlEquipmentSource" DataTextField="Equipment" DataValueField="ID" 
                                        ID="ddlEquipmentGrid" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" 
                                        AutoPostBack="true" SelectedValue='<%#Bind("EquipmentID") %>'
                                    </asp:DropDownList> 
                                </EditItemTemplate> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn> 
                                <ItemTemplate> 
                                    <asp:Label ID="Label2" Text='<%#Bind("Brand") %>' runat="server"></asp:Label> 
                                </ItemTemplate> 
                                <EditItemTemplate> 
                                    <asp:DropDownList  DataSourceID="SqlBrandSource" 
                                        DataTextField="Brand" DataValueField="ID" ID="DropDownList3" runat="server" SelectedValue='<%#Bind("BrandID") %>' /> 
                                    <asp:SqlDataSource ID="SqlBrandSource" runat="server" ConnectionString="<%$ ConnectionStrings:mobily_alexmarConnectionString %>" 
                                        SelectCommand="SELECT ID, Brand FROM tbl_Sites_EquipmentBrands WHERE (EquipmentID = @EquipmentID)"
                                        <SelectParameters> 
                                            <asp:ControlParameter ControlID="ddlEquipmentGrid" DefaultValue="0" Name="EquipmentID" 
                                                PropertyName="SelectedValue" /> 
                                        </SelectParameters> 
                                    </asp:SqlDataSource> 
                                </EditItemTemplate> 
                            </telerik:GridTemplateColumn> 
. In edit mode

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Feb 2010, 06:59 AM
Hello Shahid,

You can set the SelectCommand for the second dropdownlist's datasource from code behind as shown below:
aspx:
<telerik:GridTemplateColumn>  
    <ItemTemplate>  
        <asp:Label ID="Label1" runat="server" Text='<%#Bind("Equipment") %>'></asp:Label>  
    </ItemTemplate>  
    <EditItemTemplate>  
        <asp:DropDownList DataSourceID="SqlEquipmentSource" DataTextField="Equipment" DataValueField="ID"  
            ID="ddlEquipmentGrid" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"  
            AutoPostBack="true" SelectedValue='<%#Bind("EquipmentID") %>'>  
        </asp:DropDownList>  
    </EditItemTemplate>  
</telerik:GridTemplateColumn>  
<telerik:GridTemplateColumn>  
    <ItemTemplate>  
        <asp:Label ID="Label2" Text='<%#Bind("Brand") %>' runat="server"></asp:Label>  
    </ItemTemplate>  
    <EditItemTemplate>      
        <asp:SqlDataSource ID="SqlBrandSource" runat="server" ConnectionString="<%$ ConnectionStrings:mobily_alexmarConnectionString %>">             
        </asp:SqlDataSource>  
        <asp:DropDownList  DataSourceID="SqlBrandSource" DataTextField="Brand" DataValueField="ID" ID="DropDownList3" runat="server" />  
         
    </EditItemTemplate>  
</telerik:GridTemplateColumn>  

c#:
protected void ddlEquipmentGrid_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList dropdown1 = (DropDownList)sender; 
        GridEditableItem item = (GridEditableItem)dropdown1.NamingContainer; 
        SqlDataSource source = (SqlDataSource)item.FindControl("SqlBrandSource"); 
        source.SelectCommand = "SELECT ID, Brand FROM tbl_Sites_EquipmentBrands WHERE ID = '" + dropdown1.SelectedValue + "'"
         
    } 

-Princy.
Tags
Grid
Asked by
shahid Aleem
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or