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;
}
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).
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.
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.
You can use ClearSelection method for Dropdown list
DropDownList.ClearSelection();
Thanks
Deepu
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With