Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropdownlist Reset SelectedValue

I have a DropDownList connected to an ObjectDataSource. In my page load i set the selectedvalue to a specific value depending on the case. How can I in my method selectedindexchanged "reset" the selectedvalue so you still can choose from the other options? Or should I not use selectedvalue to set the defaultvalue of the dropdownlist?

 <asp:DropDownList ID="DropDownList" runat="server" DataSourceID="ObjectDataSource" DataTextField="Type" DataValueField="TypeId" 
    AutoPostBack="true" onselectedindexchanged="DropDownList_SelectedIndexChanged" >
            </asp:DropDownList>

protected void Page_Load(object sender, EventArgs e)
{
        int default = category.TypeId;
        DropDownList.SelectedIndex = default;

}

protected void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{

    int id = int.Parse(DropDownList.SelectedValue);
    Session["id"] = id;
}
like image 588
s.e Avatar asked Apr 12 '12 11:04

s.e


People also ask

How do I reset my drop down options?

The following HTML Markup consists of an HTML DropDownList (DropDown) control and a Button. When the Button is clicked, the Reset JavaScript function is executed. Inside this function, the SelectedIndex property of the DropDownList is set to 0 (First Item).

How do I restart a drop down in power app?

In the left navigation, click the Screen that holds the Drop down control. Select the On Visible property and enter Reset function in the formula bar. Ensure to name the Drop down control correctly.

How reset DropDown selected value in react?

By clicking on the clear icon which is shown in DropDownList element, you can clear the selected item in DropDownList through interaction. By using showClearButton property, you can enable the clear icon in DropDownList element.


1 Answers

You can use ClearSelection method for Dropdown list

DropDownList.ClearSelection();

Thanks

Deepu

like image 119
Deepu Madhusoodanan Avatar answered Sep 24 '22 09:09

Deepu Madhusoodanan