We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Store DropDownList selection in session for use as scalar in SQL query on postback.

Thread ID:





144217 Apr 25,2019 07:51 AM UTC Apr 26,2019 08:40 AM UTC ASP.NET Web Forms 1
Tags: DropDownList
Alex Jermy
Asked On April 25, 2019 07:51 AM UTC


I have a Drop Down List that is populated from a remote SQL database via a SqlDatasource control. The Drop Down List has an automatic selection which is used to populate 3 charts with data on page load. I want the user to be able to change the selection in the Drop Down List, and to store this as a session variable so that I can use it in codebehind as a scalar for the SQL query to repopulate the chart with the user's selection. Is this possible or is there a better way to populate the charts using the user's selection?

I have attached my ASP file and C# file below.



Attachment: PlanningAnalysis_3f2fc2d1.zip

Christopher Issac Sunder K [Syncfusion]
Replied On April 26, 2019 08:40 AM UTC

Hi Alex,  

Greetings from Syncfusion support. 

We suggest you to store the selected value in a session variable through “OnValueChange” event of DropDownList and use this in SQL query based on your requirement. Please refer to the below given code 

   <ej:DropDownList runat="server" ID="TradesDropDown" DataTextField="CustomerID" DataValueField="ShipCity" AutoPostBack="true" DataSourceID="SqlData" Width="200px" EnableIncrementalSearch="False" FilterType="Contains" SelectedIndex="0" OnValueSelect="TradesDropDown_ValueSelect"> 
    <asp:SqlDataSource ID="SqlData" runat="server" ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>" SelectCommand="SELECT * FROM [Orders]"> 
    <asp:Parameter Name="ShipCity" Type="String" DefaultValue="Reims" /> 
    <ej:Button runat="server" ID="btn" OnClick="btn_Click" Text="Check"></ej:Button> 


protected void Page_Load(object sender, EventArgs e) 
            if (!IsPostBack) 
                SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConnectionString"].ToString()); 
                dt = new DataTable("Order"); 
                SqlCommand cmd = new SqlCommand(); 
                cmd.Connection = myConnection; 
                cmd.CommandText = "select * from Orders"; 
                cmd.CommandType = CommandType.Text; 
                SqlDataAdapter da = new SqlDataAdapter(); 
                da.SelectCommand = cmd; 
                if ((myConnection.State == ConnectionState.Closed)) 
                Session["SqlDataSource"] = dt; 
        protected void TradesDropDown_ValueSelect(object sender, Syncfusion.JavaScript.Web.DropdownListEventArgs e) 
            Session["Selected"] = e.Value; 
        protected void btn_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e) 
            var value = Session["Selected"]; 

In our sample, we have just assigned the session variable value to a variable on button click. You can use this in SQL query based on your scenario.  Sample can be downloaded from the below link 

Please let us know if you require any further assistance. 



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon