Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. error in cascading dropdownlist

error in cascading dropdownlist

Scheduled Pinned Locked Moved ASP.NET
databasewpfwcfhelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    strawberrysh
    wrote on last edited by
    #1

    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();
                }
    

    }

    P F 2 Replies Last reply
    0
    • S strawberrysh

      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();
                  }
      

      }

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      Can you try below given way to execute reader : .ExecuteReader(CommandBehavior.CloseConne ction)

      Parwej Ahamad g.parwez@gmail.com

      S 1 Reply Last reply
      0
      • P Parwej Ahamad

        Can you try below given way to execute reader : .ExecuteReader(CommandBehavior.CloseConne ction)

        Parwej Ahamad g.parwez@gmail.com

        S Offline
        S Offline
        strawberrysh
        wrote on last edited by
        #3

        I try your code,but gave that error again :(

        P 1 Reply Last reply
        0
        • S strawberrysh

          I try your code,but gave that error again :(

          P Offline
          P Offline
          Parwej Ahamad
          wrote on last edited by
          #4

          Could you try with Data table(Dataset).

          Parwej Ahamad g.parwez@gmail.com

          S 1 Reply Last reply
          0
          • P Parwej Ahamad

            Could you try with Data table(Dataset).

            Parwej Ahamad g.parwez@gmail.com

            S Offline
            S Offline
            strawberrysh
            wrote on last edited by
            #5

            how? can you explain me more?

            1 Reply Last reply
            0
            • S strawberrysh

              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();
                          }
              

              }

              F Offline
              F Offline
              farzaneh ansari
              wrote on last edited by
              #6

              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)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups