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

dropdownlist select value

1 Answer 82 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Arun
Top achievements
Rank 1
Arun asked on 03 Jul 2013, 05:18 AM
 Hi,
       I am using rad dropdownlist in my project.In My project i show full details in gridview from database on pageload.After that i show the database values in grid view depending upon the selected values in dropdownlist till it works properly.But once i select the dropdown value it shows only the database values in grid view depending upon the selected values.I need to show the full details full details in gridview from database by selecting (select) value in dropdownlist. I want to know how to insert (select) as default value in dropdownlist.
I tried with 'default message' but it doesn't works.Please give me the solution.

Thanks,
 Arun.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 03 Jul 2013, 06:46 AM
Hi Arun,

Please have a look into the following code I tried which works fine at my end.

ASPX:
<asp:Label ID="Label1" runat="server" Text="Select Customers from "></asp:Label>
<telerik:RadDropDownList ID="RadDropDownList1" runat="server" AutoPostBack="true"
    OnSelectedIndexChanged="RadDropDownList1_SelectedIndexChanged">
    <Items>
        <telerik:DropDownListItem runat="server" Text="Select" Value="-1" Selected="true" />
        <telerik:DropDownListItem runat="server" Text="France" Value="0" />
        <telerik:DropDownListItem runat="server" Text="Brazil" Value="1" />
        <telerik:DropDownListItem runat="server" Text="USA" Value="2" />
    </Items>
</telerik:RadDropDownList>
<br />
<br />
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" DataSourceID="SqlDataSource1">
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="select CustomerID, CompanyName, City, Country from [Customers];">
</asp:SqlDataSource>

C#:
protected void populateGrid(string countryName)
{
    if (countryName.Equals("Select"))
    {
        SqlDataSource1.SelectCommand = "select CustomerID, CompanyName, City, Country from [Customers];";
        RadGrid1.Rebind();
    }
    else
    {
        SqlDataSource1.SelectCommand = "select CustomerID, CompanyName, City, Country from [Customers] where Country='" + countryName + "';";
        RadGrid1.Rebind();
    }
}
protected void RadDropDownList1_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
{
    string selectedItem = RadDropDownList1.SelectedText;
    populateGrid(selectedItem);
}

Thanks,
Shinu.
Tags
DropDownList
Asked by
Arun
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or