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.Bind (Populate) ASP.Net DropDownList in another page with Session using C# and VB.Net<p>Hi <a class="username" rel="nid@patel">nid@patel</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <p><strong>CS.aspx</strong></p> <pre class="brush: html">ID : &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtId&#34; /&gt; &lt;asp:Button Text=&#34;Redirect&#34; runat=&#34;server&#34; OnClick=&#34;Redirect&#34; /&gt;</pre> <p><strong>Default.aspx</strong></p> <pre class="brush: html">&lt;asp:DropDownList runat=&#34;server&#34; ID=&#34;ddlCountries&#34;&gt; &lt;/asp:DropDownList&gt; &lt;asp:DropDownList runat=&#34;server&#34; ID=&#34;DropDownList1&#34;&gt; &lt;asp:ListItem Text=&#34;Select&#34; Value=&#34;0&#34; /&gt; &lt;asp:ListItem Text=&#34;1&#34; Value=&#34;1&#34; /&gt; &lt;asp:ListItem Text=&#34;2&#34; Value=&#34;2&#34; /&gt; &lt;asp:ListItem Text=&#34;3&#34; Value=&#34;3&#34; /&gt; &lt;/asp:DropDownList&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>CS.aspx.cs</strong></p> <pre class="brush: csharp">protected void Redirect(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;Country&#34;, typeof(string)), new DataColumn(&#34;Id&#34;, typeof(int)) }); dt.Rows.Add(&#34;USA&#34;, 1); dt.Rows.Add(&#34;India&#34;, 2); dt.Rows.Add(&#34;France&#34;, 3); Session[&#34;dt&#34;] = dt; Session[&#34;Name&#34;] = txtId.Text; Response.Redirect(&#34;Default.aspx&#34;); }</pre> <p><strong>Default.aspx.cs</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = Session[&#34;dt&#34;] as DataTable; ddlCountries.DataSource = dt; ddlCountries.DataTextField = &#34;Country&#34;; ddlCountries.DataValueField = &#34;Id&#34;; ddlCountries.DataBind(); ddlCountries.Items.Insert(0, new ListItem(&#34;Select&#34;, &#34;0&#34;)); DropDownList1.ClearSelection(); DropDownList1.Items.FindByText(Session[&#34;Name&#34;].ToString()).Selected = true; } }</pre> <p><strong>VB.Net</strong></p> <p><strong>VB.aspx.vb</strong></p> <pre class="brush: vb">Protected Sub Redirect(ByVal sender As Object, ByVal e As EventArgs) Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;Country&#34;, GetType(String)), New DataColumn(&#34;Id&#34;, GetType(Integer))}) dt.Rows.Add(&#34;USA&#34;, 1) dt.Rows.Add(&#34;India&#34;, 2) dt.Rows.Add(&#34;France&#34;, 3) Session(&#34;dt&#34;) = dt Session(&#34;Name&#34;) = txtId.Text Response.Redirect(&#34;Default.aspx&#34;) End Sub</pre> <p><strong>Default.aspx.vb</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim dt As DataTable = TryCast(Session(&#34;dt&#34;), DataTable) ddlCountries.DataSource = dt ddlCountries.DataTextField = &#34;Country&#34; ddlCountries.DataValueField = &#34;Id&#34; ddlCountries.DataBind() ddlCountries.Items.Insert(0, New ListItem(&#34;Select&#34;, &#34;0&#34;)) DropDownList1.ClearSelection() DropDownList1.Items.FindByText(Session(&#34;Name&#34;).ToString()).Selected = True End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/6sMXcUg.gif" alt="" width="288" height="197" /></p>https://www.aspforums.net:443/Threads/929593/Bind-Populate-ASPNet-DropDownList-in-another-page-with-Session-using-C-and-VBNet/https://www.aspforums.net:443/Threads/929593/Bind-Populate-ASPNet-DropDownList-in-another-page-with-Session-using-C-and-VBNet/Fri, 09 Aug 2019 01:44:02 GMT