ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Remove Item from DropDownList on Button Click using C# in ASP.Net<p>HTML</p> <pre class="brush: html">&lt;%@ Page Title=&#34;Home Page&#34; Language=&#34;C#&#34; MasterPageFile=&#34;~/Site.Master&#34; AutoEventWireup=&#34;true&#34; CodeBehind=&#34;Default.aspx.cs&#34; Inherits=&#34;DropdownListSession._Default&#34; %&gt; &lt;asp:Content ID=&#34;BodyContent&#34; ContentPlaceHolderID=&#34;MainContent&#34; runat=&#34;server&#34;&gt; &lt;asp:DropDownList ID=&#34;DropDownList1&#34; runat=&#34;server&#34;&gt;&lt;/asp:DropDownList&gt; &lt;asp:Button ID=&#34;Button1&#34; runat=&#34;server&#34; Text=&#34;Button&#34; OnClick=&#34;Button1_Click&#34; /&gt; &lt;/asp:Content&gt;</pre> <p>C#</p> <pre class="brush: csharp">using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace DropdownListSession { public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { if (Session[&#34;ListItems&#34;] == null) { DataTable dt = DropDownItems(); DropDownList1.DataSource = dt; DropDownList1.DataTextField = &#34;Text&#34;; DropDownList1.DataValueField = &#34;Value&#34;; DropDownList1.DataBind(); Session[&#34;ListItems&#34;] = dt; } } } private DataTable DropDownItems() { DataTable dt = new DataTable(); dt.Columns.Add(&#34;Text&#34;); dt.Columns.Add(&#34;Value&#34;); dt.Rows.Add(&#34;Item1&#34;, &#34;1&#34;); dt.Rows.Add(&#34;Item2&#34;, &#34;2&#34;); dt.Rows.Add(&#34;Item3&#34;, &#34;3&#34;); dt.Rows.Add(&#34;Item4&#34;, &#34;4&#34;); return dt; } protected void Button1_Click(object sender, EventArgs e) { DataTable dt = Session[&#34;ListItems&#34;] as DataTable; ListItemCollection liCol = DropDownList1.Items; for (int i = 0; i &lt; dt.Rows.Count; i++) { ListItem li = liCol[i]; if (li.Selected) { Response.Redirect(&#34;Next.aspx&#34;); dt.Rows[i].Delete(); } } Session[&#34;ListItem&#34;] = dt; DropDownList1.DataSource = dt; DropDownList1.DataTextField = &#34;Text&#34;; DropDownList1.DataValueField = &#34;Value&#34;; DropDownList1.DataBind(); } } }</pre> <p>Thank you.</p>https://www.aspforums.net:443/Threads/203483/Remove-Item-from-DropDownList-on-Button-Click-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/203483/Remove-Item-from-DropDownList-on-Button-Click-using-C-in-ASPNet/Fri, 09 Aug 2019 19:24:06 GMT