Hi
I hav dropdown in code
After Button click I am saving this dropdown value, but after saving I want to reset dropdown and want selected item Please Select
Thank you
Hi
I hav dropdown in code
After Button click I am saving this dropdown value, but after saving I want to reset dropdown and want selected item Please Select
Thank you
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajeev KumarRank #1,334 · 1.3K reputationPosted Sep 7, 2023, 1:23 AM EDT
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DropDownList1.Items.Insert(0, new ListItem("Please Select", "Please Select")); } }Amit MohantyRank #112 · 20K reputationPosted Sep 7, 2023, 1:58 AM EDT
To reset the
DropDownListand select the "Please Select" item after a button click in ASP.NET, you can use the following code in the button's click event handler:protected void Button_Click(object sender, EventArgs e) { // Your code to save the selected value here // Reset the DropDownList to the "Please Select" item DropDownList1.SelectedIndex = 0; }Mukund Kumar46 reputationPosted Dec 20, 2023, 7:48 AM EST
Option 1: Server-Side (C#):
protected void btnSave_Click(object sender, EventArgs e) { // Reset the dropdown to the default value DropDownList1.SelectedIndex = 0; / }Option 2: Client-Side (JavaScript):
function resetDropdown() { var ddl = document.getElementById(''); ddl.selectedIndex = 0; }Anandu G NathRank #681 · 3.5K reputationPosted Dec 20, 2023, 2:07 AM EST
protected void Button_Click(object sender, EventArgs e) { // Reset the DropDownList to the "Please Select" item DropDownList1.SelectedIndex = 0; }Satyaprakash SamantarayRank #101 · 21.1K reputationPosted Dec 20, 2023, 2:59 AM EST
page load event:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DropDownList1.SelectedIndex = 0; } }Satyaprakash SamantarayRank #101 · 21.1K reputationPosted Dec 20, 2023, 3:05 AM EST
The below process is faster ur web application.
In your script under code HTML:
function ResetDropDownList() { $('#DropDownList1').val('0');and apply in ur save button