My code but its not give expected output
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
bind_dl1();
}
}
private void bind_dl1()
{
MyConnection.Open();
SqlCommand cmd = new SqlCommand("select Distinct(source) from Company_info_StanderedAfterTarget", MyConnection);
SqlDataReader dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.Items.Clear();
DropDownList1.Items.Add("---Select Source---");
DropDownList1.DataTextField="source";
//DropDownList1.DataValueField = "A_id";
DropDownList1.DataBind();
//while(dr.Read())
//{
// DropDownList1.Items.Add(dr["source"].ToString());
//}
dr.Close();
MyConnection.Close();
}
private void bind_dl2()
{
}
private void bind_gridview()
{
MyConnection.Open();
SqlCommand cmd = new SqlCommand("select * from Company_info_StanderedAfterTarget where source=@dd1",MyConnection);
cmd.Parameters.AddWithValue("@dd1",int.Parse(DropDownList1.SelectedValue));
SqlDataReader dr = cmd.ExecuteReader();
if(dr.HasRows)
{
GridView1.DataSource = dr;
GridView1.DataBind();
}
//SqlDataAdapter da = new SqlDataAdapter(cmd);
//DataTable dt = new DataTable();
//da.Fill(dt);
dr.Close();
MyConnection.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
bind_gridview();
}