<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="Send Query"></ej:Button>
<asp:Label runat="server" Text="Items matching the selected ShipCity value will be bound as dataSource of the below DropDownList when send query button is clicked"></asp:Label>
<ej:DropDownList runat="server" ID="DropDownList1" DataTextField="CustomerID" DataValueField="ShipCity">
</ej:DropDownList> |
protected void TradesDropDown_ValueSelect(object sender, Syncfusion.JavaScript.Web.DropdownListEventArgs e)
{
Session["ShipCity"] = e.Value;
}
protected void btn_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)
{
string selected = Session["ShipCity"].ToString();
dt = new DataTable("Order");
cmd.Connection = myConnection;
cmd.CommandText = "select [CustomerID] from [Orders] where [ShipCity]='" + selected + "'";
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
if ((myConnection.State == ConnectionState.Closed))
{
myConnection.Open();
}
da.Fill(dt);
Session["NewDataSource"] = dt;
DropDownList1.DataSource = Session["NewDataSource"];
} |