Click here to Skip to main content
15,895,504 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Get Loggedin Domain\Username Pin
raesark7-Jun-13 3:46
raesark7-Jun-13 3:46 
GeneralRe: Get Loggedin Domain\Username Pin
Richard Deeming7-Jun-13 3:52
mveRichard Deeming7-Jun-13 3:52 
GeneralRe: Get Loggedin Domain\Username Pin
V R Shukla10-Jun-13 1:35
V R Shukla10-Jun-13 1:35 
GeneralRe: Get Loggedin Domain\Username Pin
raesark11-Jun-13 20:18
raesark11-Jun-13 20:18 
AnswerRe: Get Loggedin Domain\Username Pin
jkirkerx8-Jun-13 8:27
professionaljkirkerx8-Jun-13 8:27 
GeneralRe: Get Loggedin Domain\Username Pin
raesark11-Jun-13 20:20
raesark11-Jun-13 20:20 
GeneralRe: Get Loggedin Domain\Username Pin
jkirkerx12-Jun-13 6:46
professionaljkirkerx12-Jun-13 6:46 
QuestionDrop Down Listnot updating when item deleted from GridView Pin
WickedFooker6-Jun-13 4:59
WickedFooker6-Jun-13 4:59 
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:
C#
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();
        ddlclassSelect.Items.Insert(0, new ListItem("Please Select", "0"));
                      
            
    }
    private void PopStud()
    {
        // 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 commandText = "SELECT * from tblStudent";
        string commandText = "SELECT * FROM tblStudent where tblStudent.stud_id in (SELECT tblSchedule.stud_id FROM tblSchedule GROUP BY tblSchedule.stud_id HAVING count(tblSchedule.stud_ID) < 3)";
        var ds9 = new DataSet();

        using (var connection9 = new OleDbConnection(connectionString))
        using (var command = new OleDbCommand(commandText, connection9))
        {
            // 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(ds9);
        }

        ddlstudID.DataSource = ds9;
        ddlstudID.DataTextField = "stud_ID";
        ddlstudID.DataValueField = "stud_ID";
        ddlstudID.DataBind();
        ddlstudID.Items.Insert(0, new ListItem("Please Select", "0"));
        
    }
    private void CheckSession()
    {
        if (Session["SecurityLevel"] == null)
        {
            Response.Redirect("~/frmLogin.aspx");
        }

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckSession();

        if (!IsPostBack)
        {
            
            PopClass();
            PopStud();

        }
        else
        {
            ddlstudID.DataBind();
            ddlclassSelect.DataBind();
            
        }
    }
    protected void AddClass_Click(object sender, EventArgs e)
    {
        // Error Check so that Please Select is not there
        if (ddlstudID.SelectedValue == "0")
        {
            lblErrStudentName.Text = "Please Select a Student.";
            lblErrStudentName.Visible = true;
        }
        else
        {
            lblErrStudentName.Text = "";
            lblErrStudentName.Visible = false;
        }
        // Error Check so that Please Select is not there
        if (ddlclassSelect.SelectedValue == "0")
        {
            lblErrClassSelect.Text = "Please Select a Class.";
            lblErrClassSelect.Visible = true;
        }
        else
        {
            lblErrClassSelect.Text = "";
            lblErrClassSelect.Visible = false;
        }


        if (lblErrStudentName.Text == "" && lblErrClassSelect.Text == "")
        if (clsDataLayer.SaveSched(Server.MapPath("eAcademy_DB.mdb"),
            (Convert.ToString(ddlstudID.SelectedValue)),
            (Convert.ToString(ddlclassSelect.SelectedValue))))
        {
            txtVerifySaved.Text = "The information was saved.";
            txtVerifySaved.Visible = true;
            GridView1.DataBind(); // Refresh the bottom part.

            // Reset the index on all drop downs
            PopClass();
            PopStud();
            ddlstudID.SelectedIndex = 0;
            ddlclassSelect.SelectedIndex = 0;
        }
        else
        {
            // Make this visable to see
            txtVerifySaved.Text = "The information was NOT saved.";
            txtVerifySaved.Visible = true;
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        PopStud();
        PopClass();
        ddlstudID.SelectedIndex = 0;
        ddlclassSelect.SelectedIndex = 0;
        
    }
}


ADDENDUM ; Going to try moving most of the code to the datalayer and see if it works better.

modified 6-Jun-13 20:48pm.

AnswerRe: Drop Down Listnot updating when item deleted from GridView Pin
WickedFooker7-Jun-13 3:08
WickedFooker7-Jun-13 3:08 
QuestionGrid View Pin
Kaushik.Subramanian6-Jun-13 3:22
Kaushik.Subramanian6-Jun-13 3:22 
AnswerRe: Grid View Pin
Richard MacCutchan6-Jun-13 4:41
mveRichard MacCutchan6-Jun-13 4:41 
QuestionGrid View Pin
Kaushik.Subramanian5-Jun-13 22:24
Kaushik.Subramanian5-Jun-13 22:24 
QuestionHow do you run the program for downloading financial data from yahoo ? Pin
forte745-Jun-13 15:51
forte745-Jun-13 15:51 
QuestionAdd Live TV in Asp.Net Pin
Jak Anil4-Jun-13 2:10
Jak Anil4-Jun-13 2:10 
AnswerRe: Add Live TV in Asp.Net Pin
Chetan Talwar6-Jun-13 17:17
Chetan Talwar6-Jun-13 17:17 
GeneralRe: Add Live TV in Asp.Net Pin
Jak Anil7-Jun-13 1:56
Jak Anil7-Jun-13 1:56 
QuestionValidationExpression complexity Pin
VikramKumarJ4-Jun-13 1:53
VikramKumarJ4-Jun-13 1:53 
AnswerRe: ValidationExpression complexity Pin
Richard Deeming4-Jun-13 1:58
mveRichard Deeming4-Jun-13 1:58 
GeneralRe: ValidationExpression complexity Pin
VikramKumarJ4-Jun-13 18:23
VikramKumarJ4-Jun-13 18:23 
QuestionBackend Image creation and loading in webpage Pin
bigjfunk3-Jun-13 17:18
bigjfunk3-Jun-13 17:18 
AnswerRe: Backend Image creation and loading in webpage Pin
Bernhard Hiller3-Jun-13 21:26
Bernhard Hiller3-Jun-13 21:26 
AnswerRe: Backend Image creation and loading in webpage Pin
Jasmine25015-Jun-13 12:34
Jasmine25015-Jun-13 12:34 
QuestionMini-registration Check if Room is booked or open Pin
WickedFooker2-Jun-13 11:11
WickedFooker2-Jun-13 11:11 
AnswerRe: Mini-registration Check if Room is booked or open Pin
Bernard Grosperrin8-Jun-13 1:30
Bernard Grosperrin8-Jun-13 1:30 
QuestionLooking for ideas for custom WYSIWYG editor for LED display Pin
Member 1008696031-May-13 10:15
Member 1008696031-May-13 10:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.