Note that there are some explanatory texts on larger screens.

plurals
  1. POFetch dropdownlist selected value upon click of a button
    primarykey
    data
    text
    <p>On an ASP.net form, I have a button and a Dropdownlist. The Dropdownlist is populated through a LinqDatasource.</p> <p>I am trying to get the selected dropdownlist value upon click of a button.</p> <p>The dropdownlist gets the list of lastname from employees table of Northwind db.</p> <p>The code behind is like this which gets the ddl value as null</p> <p>aspx page</p> <pre><code> &lt;%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Demo._Default" %&gt; &lt;form id="form1" runat="server"&gt; &lt;asp:DropDownList ID="Ddl_allGoldsets" runat="server" DataSourceID="LinqDataSource1" DataTextField="LastName" DataValueField="LastName"&gt; &lt;/asp:DropDownList&gt; &lt;asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="Demo.linqDataContext" EntityTypeName="" GroupBy="LastName" OrderGroupsBy="key" Select="new (key as LastName, it as Employees)" TableName="Employees"&gt; &lt;/asp:LinqDataSource&gt; &lt;asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /&gt; &lt;/form&gt; </code></pre> <p>codebehind</p> <pre><code>namespace Demo { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { linqDataContext dc = new linqDataContext(); DropDownList ddl = (DropDownList)Page.FindControl("Ddl_allGoldsets"); string val = ddl.SelectedValue; /* code that writes val into db*/ } } } </code></pre> <p>Above code returns null value into ddl!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload