How to set an item in a DropDownList as the default value in ASP.NET?
SomeDropDownList.DataSource =GetSomeStrings();
There are two ways to do this:
Set the SelectedValuevalue that you want to use by default DropDownList.SelectedValue = "value". This is very simple, but will result in an error if the drop-down menu already hasSelectedValue
SelectedValue
DropDownList.SelectedValue = "value"
Set the actual item DropDOwnList.Items.FindByValue("value").Selected = true;that should not result in an error if the selected item is already selected.
DropDOwnList.Items.FindByValue("value").Selected = true;
Set SelectedValueproperty
DropDownList , SelectedValue:
someDropDownList.DataSource = GetSomeStrings(); someDropDownList.DataBind(); someDropDownList.SelectedValue = "default value";
, SelectedIndex:
someDropDownList.SelectedIndex = 0;
Source: https://habr.com/ru/post/1726952/More articles:Emacs disables modes - emacsCall currentModalViewController twice? - iphoneGetting error when initializing Membership.Provider for the first time after restarting the application - c #Π Π°Π·Π΄Π΅Π» ΠΎΠ±ΡΠ΅ΠΊΡΠΎΠ² OpenGL gluUnProject - raytracingCSS Border RADIUS, which is the right style to use? border radius? -webkit-border radius? -moz is the border of the radius? - cssHeap Interlace Error - c ++how to get the identifier of the audio device to transmit to NSSound setPlaybackDeviceIdentifier: - macosObjective-C memory leak confusion - objective-cTutorials for creating a reliable small-to-medium project * nix build - unixGetting jQuery from google - javascriptAll Articles