Home > How To > Asp.net Dropdownlist Clearselection Not Working

Asp.net Dropdownlist Clearselection Not Working

Contents

Coworker throwing cigarettes out of a car, I criticized it and now HR is involved Dynamically Select Template based on template id field passed in DE Join lists by observing x-value Privacy Statement| Terms of Use| Contact Us| Advertise With Us| CMS by Umbraco| Hosted on Microsoft Azure Feedback on ASP.NET| File Bugs| Support Lifecycle current community chat Stack Overflow Meta Stack Animated plot required to leave behind trace US Election results 2016: What went wrong with prediction models? The index is zero-based. navigate here

Instead of calling ClearSelection(), do the following before calling DataBind() again:ddlTest.Items.Clear();ddlTest.SelectedValue = null; // This is key as it clears the cached selected valueOnce doing this, the sample provided works. myDropDown.DataBind(); myDropDown.Items.Insert(0, new ListItem(string.Empty, string.Empty)); myDropDown.SelectedIndex = 0; http://stackoverflow.com/a/2224636/1467453 share|improve this answer answered Jan 16 '13 at 17:59 Marco Castelo 36114 add a comment| Your Answer draft saved draft discarded Left by harry on Sep 07, 2009 10:12 PM Your comment: Title: *So what is this about? DropDownListTest.SelectedIndex = 12; Hope this saves some of your time. read the full info here

How To Clear Dropdownlist In Asp.net Using C#

Code ladder, Cops What is the point of update independent rendering in a game loop? asp.net webforms drop-down-menu share|improve this question edited Oct 14 '08 at 12:52 Alexander Prokofyev 19.1k2484104 asked Sep 17 '08 at 8:46 Alex add a comment| 7 Answers 7 active oldest votes Does the Rothschild family own most central banks? Join lists by observing x-value How does Gandalf end up on the roof of Isengard?

Join them; it only takes a minute: Sign up Dropdownlist Reset SelectedValue up vote 0 down vote favorite I have a DropDownList connected to an ObjectDataSource. Not sure why you were downvoted - sorry if my comment cause that :( –womp Feb 8 '10 at 20:33 this one will clear the item list and in Another way to show convergence of alternating series Can a giant spoon be utilised as a weapon more hot questions question feed about us tour help blog chat data legal privacy C# Dropdownlist Clear Selection Browse other questions tagged c# asp.net drop-down-menu or ask your own question.

drop-down-menu asp.net-3.5 share|improve this question asked Feb 8 '10 at 20:25 Eyla 1,9811653100 add a comment| 6 Answers 6 active oldest votes up vote 14 down vote accepted You can add How To Clear The Selected Value Of Dropdownlist In C# US Election results 2016: What went wrong with prediction models? Do you know a VB example? –Obsidian May 9 '13 at 15:11 see the Edit its equal to New List(Of String)() in Vb.net –wizpert May 9 '13 at 16:09 http://stackoverflow.com/questions/10122696/dropdownlist-reset-selectedvalue And clear the list on data change.

Adding the extra option wouldn't work unless you set the AppendDataBoundItems to true and then if you bind again you would have to do the Clear() anyway to make sure you Asp Net Reset Dropdownlist This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL) Top Experts Last 24hrsThis month OriginalGriff 190 ppolymorphe 100 Dave Kreskowiak You cannot clear the selection from every item in the list at the same time. Coworker throwing cigarettes out of a car, I criticized it and now HR is involved What does the actual path of air within a turbojet engine look like?

How To Clear The Selected Value Of Dropdownlist In C#

myDropDownList.DataSource = DataAccess.GetDropDownItems(); // Psuedo Code myDropDownList.DataTextField = "Value"; myDropDownList.DataValueField = "Id"; myDropDownList.DataBind(); myDropDownList.Items.Insert(0, new ListItem("Please select", "")); Will add the 'Please select' drop down item to the top. Sold my Canon EOS 5D Mark II and buyer says images are not in focus Mimsy were the Borogoves - why is "mimsy" an adjective? How To Clear Dropdownlist In Asp.net Using C# Should I report it? How To Clear The Selected Value Of Dropdownlist In Jquery Not the answer you're looking for?

Optional Password I have read and agree to the Terms of Service and Privacy Policy Please subscribe me to the CodeProject newsletters Submit your solution! Please enter a comment. Blog Sign in Join ASP.NET Home Get Started Learn Hosting Downloads Community Overview Community Spotlight Articles of the Day What's new Community Blogs ASP.NET Team Events Hall Of Fame MSDN Samples Why are progress bars so inaccurate? Reset Dropdown List C#

Pick Randomly Between -1 or 1 Why were pre-election polls and forecast models so wrong about Donald Trump? "president-elect" grammatically correct? Email: (never displayed)*Email is optional, but if you enter one at least make sure it is valid. (will show your gravatar) Comment: *I do want to hear your thoughts. An item is always selected in the DropDownList control. Your Email This email is in use.

By default, dropdownlist have first item as selected item.So when i select another items it returns the first index only. Clear Selected Item In Dropdownlist C# DETAILS ATTACH A FILE EDIT THIS ITEM Assign To Item can only be reassigned when it is active. Should I report it?

The case of the Stairs What is the point of update independent rendering in a game loop?

more hot questions question feed lang-cs about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation What I am doing wrong? MathSciNet review alert? How To Clear Selected Item In Dropdownlist In Jquery What is the more appropriate adjectival form of Trump?

Upvoted –SearchForKnowledge May 15 '14 at 13:27 add a comment| up vote 1 down vote just compiled your code and the only thing that is missing from it is that you TOP TIP Still want a default list item adding to your dropdown but need to rebind data? Why doesn't the UK produce hazelnuts, chestnuts and walnuts, despite having suitable climatic and horticultural conditions? See more: C# ASP.NET DropDownList Cookie List listOfCountry = MyDataBase.Country.Liste.Complete;//get list of Country from database controls.DropDownList.Bind(listOfCountry, ddlCountry );//binding list to ddl if (Request.Cookies["SelectedCountry"] != null) { string Countryid=Request.Cookies["SelectedCountry"].Value; controls.DropDownList.SelectItem(ddlCountry, Countryid);//select item

Use AppendDataBoundItems="False" to prevent duplication data on postback and then directly after binding your dropdownlist insert a new default list item.