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. Drop Down Listnot updating when item deleted from GridView

Drop Down Listnot updating when item deleted from GridView

Scheduled Pinned Locked Moved ASP.NET
csshelpdesignsysadminquestion
2 Posts 1 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.
  • W Offline
    W Offline
    WickedFooker
    wrote on last edited by
    #1

    I have a drop down list that is populated by reading the student's names that have less than 3 classes in a semester. It is also reading a class list that has a population of less than 10. I can get it to work if i ADD a NEW student and then that student has reached 3 classes it will remove his name from the drop down, and the same with the class when I click add it removes BOTH the student (if over 3) and the class (if more than 10). However .. Here is the problem. When I delete a student from the schedule it does not update the drop down list. I have several databinds() but it does not appear to fix things. Ideally when it deletes a student from a class and let's say that student was formerly locked out (i.e. has 3 classes) - well then he has 2 and it should add his name if so to the drop down list (which is not updating). Thew same with CLASS since he dropped the class the count went down and if the class was full before it might not be now. Appreciate any insight you can offer. Weird how it works one way but not the other. In other words the grid is what is causing the problem - it updates but not the top part (drop down) even though I have databinds. Here is the code:

    using System;
    using System.Data;
    using System.Data.OleDb;
    using System.Web.UI.WebControls;

    public partial class frmRegisterStudent : System.Web.UI.Page
    {
    private void PopClass()
    {
    // Populate Class and add Please Select
    // Populate Student and add Please Select
    string path = Server.MapPath("eAcademy_DB.mdb");
    string connectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
    string commandText10 = "SELECT class_ID FROM tblClass WHERE class_ID NOT IN (SELECT class_ID FROM tblschedule GROUP BY class_ID HAVING COUNT(class_ID) >= 10)";

        var ds10 = new DataSet();
    
        using (var connection10 = new OleDbConnection(connectionString))
        using (var command = new OleDbCommand(commandText10, connection10))
        {
            // OleDbCommand uses positional, rather than named, parameters.
            // The parameter name doesn't matter; only the position.
            command.Parameters.AddWithValue("@p0", ddlstudID.SelectedValue);
    
            var adapter = new OleDbDataAdapter(command);
            adapter.Fill(ds10);
        }
    
        ddlclassSelect.DataSource = ds10;
        ddlclassSelect.DataTextField = "class\_ID";
        ddlclassSelect.DataValueField = "class\_ID";
        ddlclassSelect.DataBind();
        ddlcla
    
    W 1 Reply Last reply
    0
    • W WickedFooker

      I have a drop down list that is populated by reading the student's names that have less than 3 classes in a semester. It is also reading a class list that has a population of less than 10. I can get it to work if i ADD a NEW student and then that student has reached 3 classes it will remove his name from the drop down, and the same with the class when I click add it removes BOTH the student (if over 3) and the class (if more than 10). However .. Here is the problem. When I delete a student from the schedule it does not update the drop down list. I have several databinds() but it does not appear to fix things. Ideally when it deletes a student from a class and let's say that student was formerly locked out (i.e. has 3 classes) - well then he has 2 and it should add his name if so to the drop down list (which is not updating). Thew same with CLASS since he dropped the class the count went down and if the class was full before it might not be now. Appreciate any insight you can offer. Weird how it works one way but not the other. In other words the grid is what is causing the problem - it updates but not the top part (drop down) even though I have databinds. Here is the code:

      using System;
      using System.Data;
      using System.Data.OleDb;
      using System.Web.UI.WebControls;

      public partial class frmRegisterStudent : System.Web.UI.Page
      {
      private void PopClass()
      {
      // Populate Class and add Please Select
      // Populate Student and add Please Select
      string path = Server.MapPath("eAcademy_DB.mdb");
      string connectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
      string commandText10 = "SELECT class_ID FROM tblClass WHERE class_ID NOT IN (SELECT class_ID FROM tblschedule GROUP BY class_ID HAVING COUNT(class_ID) >= 10)";

          var ds10 = new DataSet();
      
          using (var connection10 = new OleDbConnection(connectionString))
          using (var command = new OleDbCommand(commandText10, connection10))
          {
              // OleDbCommand uses positional, rather than named, parameters.
              // The parameter name doesn't matter; only the position.
              command.Parameters.AddWithValue("@p0", ddlstudID.SelectedValue);
      
              var adapter = new OleDbDataAdapter(command);
              adapter.Fill(ds10);
          }
      
          ddlclassSelect.DataSource = ds10;
          ddlclassSelect.DataTextField = "class\_ID";
          ddlclassSelect.DataValueField = "class\_ID";
          ddlclassSelect.DataBind();
          ddlcla
      
      W Offline
      W Offline
      WickedFooker
      wrote on last edited by
      #2

      FIXED! I hard coded the Delete Command to the Grid like this:

      In the code back did this:

      protected void LinkButton_Click(Object sender, CommandEventArgs e)
      {

          if (e.CommandArgument != null)
          {
              
              string MainString = e.CommandArgument.ToString();
              string\[\] Split = MainString.Split(new Char\[\] { '&' });
              //SHOW RESULT of SPLIT
              Session\["ClassID"\] = (Convert.ToString(Split\[0\]));
              Session\["StudID"\] =  (Convert.ToString(Split\[1\]));
                          
              clsDataLayer.RemoveSchedule(Server.MapPath("eAcademy\_DB.mdb"),(String)Session\["StudID"\],(String)Session\["ClassID"\]);
      
              PopClass();
              PopStud();
              gvTeachers.DataBind();
              Session\["ClassID"\] = null;
              Session\["StudID"\] = null;    
          }
      
      }
      

      AND Lastly in my clsdatalayer:

      public static void RemoveSchedule(String path, String StudX, String ClassX)
      {
      //declaring database variables to access the database Addressbook
      OleDbConnection dbConn = null;
      OleDbCommand dbCmd;
      OleDbDataReader dr;
      String strConnection;
      String strSQL;

              {
                  strConnection = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
                  dbConn = new OleDbConnection(strConnection);
                  dbConn.Open();
                  strSQL = "DELETE \* FROM tblSchedule WHERE (class\_ID=? and stud\_ID=?)";
                  dbCmd = new OleDbCommand(strSQL, dbConn);
                  dbCmd.Parameters.Add(new OleDbParameter("class\_ID", ClassX));
                  dbCmd.Parameters.Add(new OleDbParameter("stud\_ID", StudX));
                  dr = dbCmd.ExecuteReader();
                  dr.Read();
                  dbConn.Close();
                  
      
              }
              
          }
      

      Now to just add back the TRY Catch and it should be working nicely.

      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