{"id":4097,"date":"2022-12-29T15:37:59","date_gmt":"2022-12-29T15:37:59","guid":{"rendered":"https:\/\/isophal.com\/?p=4097"},"modified":"2022-12-29T15:38:01","modified_gmt":"2022-12-29T15:38:01","slug":"how-to-use-dropdownlist-control-in-asp-net-c","status":"publish","type":"post","link":"https:\/\/isophal.com\/news\/2022\/12\/29\/4097.html\/","title":{"rendered":"How to Use DropDownList Control in ASP.Net C#"},"content":{"rendered":"\n<p>The DropDownList control is asp.net web server control. we can use dropdownlist control for hold group of items. The dropdownlist control is used to store the multiple items and allow user to select only one item from it.<\/p>\n\n\n\n<p>The dropdownlist control is also known as combo box control. In dropdownlist control we&nbsp;<strong>can store multiple items but we can select only one item at a time<\/strong>, that\u2019s why it is also&nbsp;<strong>known as Single Row Selection Box.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DropdownList Control Syntax :<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>&lt;asp:DropDownListID=\u201cDropDownList1\u201c\u00a0runat=\u201cserver\u201c>&lt;\/asp:DropDownList><\/code><\/pre>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>There is only\u00a0 one difference between dropdownlist control and listbox control \u2013 SelectionMode.\u00a0<strong>The dropdownlist has no SelectionMode<\/strong>, so we can not select multiple item from dropdownlist.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownList Control Example in ASP.Net C#<\/h3>\n\n\n\n<p>Here, we understand the dropdownlist control with an asp.net example.<\/p>\n\n\n\n<p>Create a new web application in asp.net with a web forms. below screen shows how to take dropdownlist control on web page from toolbox.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"472\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-47-1024x472.png\" alt=\"\" class=\"wp-image-4098\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-47-1024x472.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-47-600x276.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-47-300x138.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-47-768x354.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-47-1536x708.png 1536w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-47-1170x539.png 1170w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-47-585x270.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-47.png 1832w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now, for add new items in dropdownlist go to the Items property shows like below asp.net figure.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"526\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-48-1024x526.png\" alt=\"\" class=\"wp-image-4099\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-48-1024x526.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-48-600x308.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-48-300x154.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-48-768x395.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-48-1536x789.png 1536w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-48-1170x601.png 1170w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-48-585x301.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-48.png 1572w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">How to use DropDownList control in ASP.Net C#.<\/figcaption><\/figure>\n\n\n\n<p>In dropdownlist control all the elements are known as items of dropdownlist, and each items consist with text and value attributes.<\/p>\n\n\n\n<p>If we add items in to dropdwonlist control we must provide Text and Value for each items.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Text =\u00a0<\/strong>Text Property specify the Text display in the dropdownlist.<\/li>\n\n\n\n<li><strong>Value =<\/strong>\u00a0The value property is invisible value, but we can get the value while programming.<\/li>\n<\/ul>\n\n\n\n<p>Here is the html code of dropdownlist control with five items.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;asp:DropDownList ID=\"DropDownList1\" runat=\"server\" Font-Size=\"16pt\" Width=\"247px\">\r\n                            &lt;asp:ListItem Value=\"1\">C\/C++&lt;\/asp:ListItem>\r\n                            &lt;asp:ListItem Value=\"2\">C#&lt;\/asp:ListItem>\r\n                            &lt;asp:ListItem Value=\"3\">VB.Net&lt;\/asp:ListItem>\r\n                            &lt;asp:ListItem Value=\"4\">Pythom&lt;\/asp:ListItem>\r\n                            &lt;asp:ListItem Value=\"5\">JavaScript&lt;\/asp:ListItem>\r\n                            &lt;asp:ListItem Value=\"6\">PHP&lt;\/asp:ListItem>\r\n                        &lt;\/asp:DropDownList>\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"530\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-49-1024x530.png\" alt=\"\" class=\"wp-image-4100\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-49-1024x530.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-49-600x311.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-49-300x155.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-49-768x398.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-49-585x303.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-49.png 1089w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">How to use DropDownList control in ASP.Net C#.<\/figcaption><\/figure>\n\n\n\n<p>All server side control has its own properties and events. below list shows basic properties of Dropdownlist control.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Properties<\/th><th>Description<\/th><\/tr><tr><td>ID<\/td><td>Identification name of control.<\/td><\/tr><tr><td>BackColor<\/td><td>It is used to set background color of control.<\/td><\/tr><tr><td>ForColor<\/td><td>It is used to set text color of the control.<\/td><\/tr><tr><td>ToolTip<\/td><td>It displays a text on control when mouse over on it.<\/td><\/tr><tr><td>TabIndex<\/td><td>It is used&nbsp;manage tab order of control.<\/td><\/tr><tr><td>CssClass<\/td><td>It is used to apply style on control.<\/td><\/tr><tr><td>Enable<\/td><td>true\/false \u2013 used to enable or disable control.<\/td><\/tr><tr><td>Enable Theming<\/td><td>true\/false \u2013 It is used to enable or disable effect of theme on control.<\/td><\/tr><tr><td>CausesValidation<\/td><td>true\/false \u2013 It is used to enable or disable validation effect on control<\/td><\/tr><tr><td>Visible<\/td><td>true\/false \u2013 It is used to hide or visible control on web page.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Below lists show important properties of Dropdownlist control, which is use in programming side.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Properties<\/th><th>Description<\/th><\/tr><tr><td>Items<\/td><td>It shows the collection of item in the Dropdownlist.<\/td><\/tr><tr><td>DropDownList1.Items.Count<\/td><td>Return the total count of items in the dropdownlist.<\/td><\/tr><tr><td>DropDownList1.Items.Add(\u201cItemName\u201d)<\/td><td>Add the new item in to the dropdownlist control.<\/td><\/tr><tr><td>DropDownList1.Items.Insert(int index, \u201cItemName\u201d)<\/td><td>Add the new item at specific position in dropdownlist control.<\/td><\/tr><tr><td>DropDownList1.Items.Remove(\u201cItemName\u201d)<\/td><td>Remove the item from the dropdownlist control.<\/td><\/tr><tr><td>DropDownList1.Items.RemoveAt(int index)<\/td><td>Remove the item from the dropdownlist at desired position index.<\/td><\/tr><tr><td>DropDownList1.Items.Clear()<\/td><td>Clear all the items from dropdownlist control.<\/td><\/tr><tr><td>DropDownList1.SelectedItem.Text<\/td><td>Returns the Text value of selected item of the dropdownlist.<\/td><\/tr><tr><td>DropDownList1.SelectedValue<\/td><td>Returns the Value property of the selected item of the dropdownlist.<\/td><\/tr><tr><td>DropDownList1.SelectedIndex<\/td><td>Returns the Index of selected item of dropdownlist. (Index always start from Zero).<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Now, let\u2019s see all programming properties with C# Example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownList1.Items.Count<\/h3>\n\n\n\n<p>Below example show the total number of item count in dropdownlist control.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"989\" height=\"600\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-51.png\" alt=\"\" class=\"wp-image-4102\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-51.png 989w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-51-600x364.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-51-300x182.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-51-768x466.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-51-585x355.png 585w\" sizes=\"auto, (max-width: 989px) 100vw, 989px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void btncount_Click(object sender, EventArgs e)<br>{<br>Label1.Text = \"The Count = \" + DropDownList1.Items.Count.ToString();<br>}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"431\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-52-1024x431.png\" alt=\"\" class=\"wp-image-4103\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-52-1024x431.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-52-600x253.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-52-300x126.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-52-768x324.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-52-585x246.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-52.png 1073w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">How to get total number of items count in dropdownlist in asp.net<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownlList1.SelectedItem.Text<\/h3>\n\n\n\n<p>Example : How to get selected item from dropdownlist control in asp.net.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"378\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-53-1024x378.png\" alt=\"\" class=\"wp-image-4104\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-53-1024x378.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-53-600x222.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-53-300x111.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-53-768x284.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-53-585x216.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-53.png 1042w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void btnselected_text_Click(object sender, EventArgs e)<br>{<br>Label1.Text = \"Text = \" + DropDownList1.SelectedItem.Text;<br>}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"426\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-54-1024x426.png\" alt=\"\" class=\"wp-image-4105\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-54-1024x426.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-54-600x249.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-54-300x125.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-54-768x319.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-54-585x243.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-54.png 1073w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Get SelectedItem from dropdownlist control in asp.net C#<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownList1.SelectedValue<\/h3>\n\n\n\n<p>Example : How to get Selected Value from dropdownlist control in asp.net.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void btnselected_value_Click(object sender, EventArgs e)<br>{<br>Label1.Text = \"Value = \" + DropDownList1.SelectedValue;<br>}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"438\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-55-1024x438.png\" alt=\"\" class=\"wp-image-4106\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-55-1024x438.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-55-600x257.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-55-300x128.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-55-768x329.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-55-585x250.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-55.png 1072w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Get SelectedValue from dropdownlist control in asp.net C#.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownList1.SelectedIndex<\/h3>\n\n\n\n<p>Example: Get Selected Index in dropdownlist control in asp.net.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void btn_index_Click(object sender, EventArgs e)<br>{<br>Label1.Text = \"Index = \" + DropDownList1.SelectedIndex.ToString();<br>}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"432\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-56-1024x432.png\" alt=\"\" class=\"wp-image-4107\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-56-1024x432.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-56-600x253.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-56-300x126.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-56-768x324.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-56-585x247.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-56.png 1075w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">SelectedIndex in dropdownlist control in asp.net C#<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownList1.Items.Clear()<\/h3>\n\n\n\n<p>Example : Clear all items in dropdownlist control.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void btn_clear_Click(object sender, EventArgs e)<br>{<br>DropDownList1.Items.Clear();<br>Label1.Text = \"ListBox Cleared\";<br>}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-57-1024x430.png\" alt=\"\" class=\"wp-image-4108\" width=\"840\" height=\"352\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-57-1024x430.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-57-600x252.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-57-300x126.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-57-768x323.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-57-585x246.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-57.png 1076w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><figcaption class=\"wp-element-caption\">How to use clear() in dropdownlist control in asp.net C#.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownList1.Items.Add(\u201ctext\u201d);<\/h3>\n\n\n\n<p>Example : Add new item in dropdownlist control.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void btn_add_Click(object sender, EventArgs e)<br>{<br>DropDownList1.Items.Add(\"ASP.Net\");<br>Label1.Text = \"Item Added\";<br>}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"420\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-58-1024x420.png\" alt=\"\" class=\"wp-image-4109\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-58-1024x420.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-58-600x246.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-58-300x123.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-58-768x315.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-58-585x240.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-58.png 1085w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">How to add new item in dropdownlist control in asp.net C#.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownList1.Items.Remove(\u201ctext\u201d)<\/h3>\n\n\n\n<p>Example : Remove items from dropdownlist control.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void btn_remove_Click(object sender, EventArgs e)<br>{<br>DropDownList1.Items.Remove(\"PHP\");<br>Label1.Text = \"Item Removed\";<br>}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"430\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-59-1024x430.png\" alt=\"\" class=\"wp-image-4110\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-59-1024x430.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-59-600x252.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-59-300x126.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-59-768x322.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-59-585x246.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-59.png 1077w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownList1.Items.Insert(int index, \u201ctext\u201d);<\/h3>\n\n\n\n<p>Example : Add new item at specific location in dropdownlist control. The index is the indicate the location of newly added item in dropdownlist control.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"531\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-60-1024x531.png\" alt=\"\" class=\"wp-image-4111\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-60-1024x531.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-60-600x311.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-60-300x155.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-60-768x398.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-60-585x303.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-60.png 1069w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void btn_add_Click(object sender, EventArgs e)<br>{<br>DropDownList1.Items.Insert(2, \"ASP.Net\");<br>Label1.Text = \"Item Inserted\";<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">DropDownList1.Items.RemoveAt(int index)<\/h3>\n\n\n\n<p>Example : Remove items from dropdownlist control at specify the index location. The index start from zero.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void btn_remove_Click(object sender, EventArgs e)<br>{<br>DropDownList1.Items.RemoveAt(2);<br>Label1.Text = \"Item Removed\";<br>}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"489\" src=\"https:\/\/isophal.com\/wp-content\/uploads\/2022\/12\/image-61-1024x489.png\" alt=\"\" class=\"wp-image-4112\" srcset=\"https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-61-1024x489.png 1024w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-61-600x287.png 600w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-61-300x143.png 300w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-61-768x367.png 768w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-61-585x280.png 585w, https:\/\/isophal.com\/news\/wp-content\/uploads\/2022\/12\/image-61.png 1069w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The C# code behind code for all buttons click events.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Web;\r\nusing System.Web.UI;\r\nusing System.Web.UI.WebControls;\r\n\r\nnamespace D2ASPdoNet\r\n{\r\n    public partial class DropDownList_Control_in_ASP_Net : System.Web.UI.Page\r\n    {\r\n        protected void Page_Load(object sender, EventArgs e)\r\n        {\r\n\r\n        }\r\n\r\n        protected void btncount_Click(object sender, EventArgs e)\r\n        {\r\n            Label1.Text = \"The Count = \" + DropDownList1.Items.Count.ToString();\r\n        }\r\n\r\n        protected void btnselected_text_Click(object sender, EventArgs e)\r\n        {\r\n            Label1.Text = \"Text = \" + DropDownList1.SelectedItem.Text;\r\n        }\r\n\r\n        protected void btnselected_value_Click(object sender, EventArgs e)\r\n        {\r\n            Label1.Text = \"Value = \" + DropDownList1.SelectedValue;\r\n        }\r\n\r\n        protected void btn_index_Click(object sender, EventArgs e)\r\n        {\r\n            Label1.Text = \"Index = \" + DropDownList1.SelectedIndex.ToString();\r\n        }\r\n\r\n        protected void btn_clear_Click(object sender, EventArgs e)\r\n        {\r\n            DropDownList1.Items.Clear();\r\n            Label1.Text = \"ListBox Cleared\";\r\n        }\r\n\r\n        protected void btn_add_Click(object sender, EventArgs e)\r\n        {\r\n            DropDownList1.Items.Insert(2, \"ASP.Net\");\r\n            Label1.Text = \"Item Inserted\";\r\n        }\r\n\r\n        protected void btn_remove_Click(object sender, EventArgs e)\r\n        {\r\n            DropDownList1.Items.RemoveAt(2);\r\n            Label1.Text = \"Item Removed\";\r\n        }\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<p>We hope that this asp.net tutorial helped you to understand about DropDownList control.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The DropDownList control is asp.net web server&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4113,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189,140],"tags":[191],"class_list":["post-4097","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net","category-programming","tag-asp-net"],"_links":{"self":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/comments?post=4097"}],"version-history":[{"count":1,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4097\/revisions"}],"predecessor-version":[{"id":4114,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4097\/revisions\/4114"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media\/4113"}],"wp:attachment":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media?parent=4097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/categories?post=4097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/tags?post=4097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}