Hi ,
Check this
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (
SqlConnection con =
new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("usp_test_all", con))
{
cmd.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "OrderAmount";
DropDownList1.DataValueField = "orderID";
DropDownList1.DataBind();
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
using (
SqlConnection con =
new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("usp_test", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", DropDownList1.SelectedValue);
DataTable dt = new DataTable();
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
Best Regards
M.Mitwalli