Hi ,
Check this
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown"> </asp:gridview>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (
SqlConnection con =
new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("usp_Get_All", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adpt.Fill(dt);
DropDownList2.DataSource = dt;
DropDownList2.DataTextField = "name";
DropDownList2.DataValueField = "id";
cmd.Dispose();
}
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
using (
SqlConnection con =
new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("usp_Search_All", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("id", DropDownList2.SelectedValue);
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adpt.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
cmd.Dispose();
}
}
Best Regards
M.Mitwalli