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">
</ej:DropDownList>
<asp:SqlDataSource ID="SqlData" runat="server" ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>" SelectCommand="SELECT * FROM [Orders]">
<SelectParameters>
<asp:Parameter Name="ShipCity" Type="String" DefaultValue="Reims" />
</SelectParameters>
</asp:SqlDataSource>
<ej:Button runat="server" ID="btn" OnClick="btn_Click" Text="Check"></ej:Button> |
Aspx.CS:
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))
{
myConnection.Open();
}
da.Fill(dt);
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.
Thanks,
Christo