error in cascading dropdownlist
-
Hi i have two dropdownlist.i bind somthing to first dropdownlist from database.I want when I select an item from dropdownlist1 see some item in dropdownlist2 .but when i select item from dropdownlist1 ,I give this error. i wrote this code but give error : error: invalid attempt to call FeildCount when reader is cloused for binding item to dropdownlist1 i wrote this code in page load:
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "dbo.StoredProcedure19";
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "category_name";
DropDownList2.DataValueField = "category_id";
DropDownList1.DataBind();
con.Close();
dr.Close();
}in select index change of dropdownlist1
protected void drse(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "dbo.StoredProcedure21"; cmd.Parameters.AddWithValue("@category\_id", DropDownList1.SelectedItem.Value.ToString()); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { DropDownList2.DataSource = dr; DropDownList2.DataTextField = "type"; DropDownList2.DataValueField = "id\_type"; DropDownList1.DataBind(); con.Close(); dr.Close(); }
}
-
Hi i have two dropdownlist.i bind somthing to first dropdownlist from database.I want when I select an item from dropdownlist1 see some item in dropdownlist2 .but when i select item from dropdownlist1 ,I give this error. i wrote this code but give error : error: invalid attempt to call FeildCount when reader is cloused for binding item to dropdownlist1 i wrote this code in page load:
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "dbo.StoredProcedure19";
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "category_name";
DropDownList2.DataValueField = "category_id";
DropDownList1.DataBind();
con.Close();
dr.Close();
}in select index change of dropdownlist1
protected void drse(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "dbo.StoredProcedure21"; cmd.Parameters.AddWithValue("@category\_id", DropDownList1.SelectedItem.Value.ToString()); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { DropDownList2.DataSource = dr; DropDownList2.DataTextField = "type"; DropDownList2.DataValueField = "id\_type"; DropDownList1.DataBind(); con.Close(); dr.Close(); }
}
Can you try below given way to execute reader : .ExecuteReader(CommandBehavior.CloseConne ction)
Parwej Ahamad g.parwez@gmail.com
-
Can you try below given way to execute reader : .ExecuteReader(CommandBehavior.CloseConne ction)
Parwej Ahamad g.parwez@gmail.com
I try your code,but gave that error again :(
-
I try your code,but gave that error again :(
Could you try with Data table(Dataset).
Parwej Ahamad g.parwez@gmail.com
-
Could you try with Data table(Dataset).
Parwej Ahamad g.parwez@gmail.com
how? can you explain me more?
-
Hi i have two dropdownlist.i bind somthing to first dropdownlist from database.I want when I select an item from dropdownlist1 see some item in dropdownlist2 .but when i select item from dropdownlist1 ,I give this error. i wrote this code but give error : error: invalid attempt to call FeildCount when reader is cloused for binding item to dropdownlist1 i wrote this code in page load:
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "dbo.StoredProcedure19";
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "category_name";
DropDownList2.DataValueField = "category_id";
DropDownList1.DataBind();
con.Close();
dr.Close();
}in select index change of dropdownlist1
protected void drse(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "dbo.StoredProcedure21"; cmd.Parameters.AddWithValue("@category\_id", DropDownList1.SelectedItem.Value.ToString()); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { DropDownList2.DataSource = dr; DropDownList2.DataTextField = "type"; DropDownList2.DataValueField = "id\_type"; DropDownList1.DataBind(); con.Close(); dr.Close(); }
}
hi you can use from this code for cascading dropdownlist CascadingFieldQueryDD.SelectedValue ="every strig you must selected in dropdownlist that controlid is your cascading";
Farzaneh Ansary(Fafar)