DropDownList Control Data Source

Background: I’m working with a C# module in DotNetNuke vers. 4.93. The module is a Web Application Project. I am currently:
a.) Studying a DropDownList control (cboStudentSelection) in EditGrades.ascx.cs. The control lists the portal users.

The Web Application Project is Mitchel Sellers’ Course Gradebook module. The Course Gradebook is a C# module, which is a free download from his web site.

Question: What is the data source for the DropDownList (cboStudentSelection)?

Screen Shots:
The attached screen shots show how the DropDownList works as well as the values of the variables as you step through the code.
File: EditGrades.ascx.cs

using System;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using ICG.CourseGradebook.Components;

namespace ICG.Modules.CourseGradebook
{
    /// <summary>
    /// This page handles all acutual user grading for the module
    /// </summary>
    public partial class EditGrades : PortalModuleBase , IActionable 
    {
        /// <summary>
        /// On the initial page load we obtain a list of students and also ensure that we are properly associated to a course
        /// </summary>
        /// <param name=”sender”></param>
        /// <param name=”e”></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Ensure the module is configured
                object oCourseId = Settings[“ICG_CourseGradebook_AssociatedCourse”];
                if (oCourseId != null)
                {
                    //Get the course information to bind the list of users
                    CourseGradebookController oController = new CourseGradebookController();
                    CourseSettingInfo oSettings = oController.GetCourseSetting(int.Parse(Settings[“ICG_CourseGradebook_AssociatedCourse”].ToString()), PortalId);
                    DotNetNuke.Entities.Users.UserRoleInfo oTest = new DotNetNuke.Entities.Users.UserRoleInfo();
                    
                    //Bind the users
                    DotNetNuke.Security.Roles.RoleController oRoleController = new DotNetNuke.Security.Roles.RoleController();
                    BindStudentsToGrid(oRoleController.GetUserRolesByRoleName(PortalId, oSettings.StudentRole));
                    
                    //Ensure users are available
                    if (cboStudentSelection.Items.Count > 0)
                    {
                        //Localize content
                        LocalizePageControls(oSettings.CourseDisplayName);

                        //Load first user
                        cboStudentSelection_SelectedIndexChanged(sender, e);
                    }
                    else
                    {
                        //No students
                        //Hide panels
                        pnlStudentSelection.Visible = false;
                        pnlStudentsGradebook.Visible = false;
                        
                        //Display module message
                        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, GetLocalizedText(“NoStudents”), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning);
                    }
                }
                else
                {
                    //Hide panels
                    pnlStudentSelection.Visible = false;
                    pnlStudentsGradebook.Visible = false;

                    //Display module message
                    DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, GetLocalizedText(“NotConfigured”), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning);
                }
            }
        }

        #region Helper Methods
        /// <summary>
        /// This method handles the localization of strings that are not automatically handled (Buttons etc...)
        /// </summary>
        /// <param name=”courseName”>The name of the course, used to update the “student gradebook” display</param>
        private void LocalizePageControls(string courseName)
        {
            hlReturn.NavigateUrl = Globals.NavigateURL(TabId);
            lblStudentGradebook.Text = GetLocalizedText(“lblStudentGradebook”).Replace(“[COURSE]”, courseName);

            //localize the grid
            Localization.LocalizeDataGrid(ref dgrGradeDetail, this.LocalResourceFile);
            ((ButtonColumn)dgrGradeDetail.Columns[9]).Text = GetLocalizedText(“EditScoreLink”);

            //Delete confirmation message
            btnDelete.OnClientClick = “javascript:return confirm(‘” + GetLocalizedText(“DeleteConfirmMessage”) + “’);”;
        }
        /// <summary>
        /// This method is used to get 1 localized string
        /// </summary>
        /// <param name=”keyname”></param>
        /// <returns></returns>
        private string GetLocalizedText(string keyname)
        {
            return Localization.GetString(keyname, LocalResourceFile);
        }
        /// <summary>
        /// This method is used to bind the students to the grid
        /// </summary>
        /// <param name=”oList”></param>
        private void BindStudentsToGrid(System.Collections.ArrayList oList)
        {
            //Get our setting
            object rawDisplaySetting = Settings[“ICG_CourseGradebook_StudentDisplayMode”];
            string formattedDisplaySeting = “”;

            if (rawDisplaySetting != null)
                formattedDisplaySeting = rawDisplaySetting.ToString();
            else
                formattedDisplaySeting = “Display Name”;

            //Now, loop through the entries and bind to our object
            foreach (object oCurrent in oList)
            {
                //Cast to the proper object
                UserRoleInfo oInfo = (UserRoleInfo)oCurrent;

                //Get the user info
                DotNetNuke.Entities.Users.UserInfo oUser = UserController.GetUser(PortalId, oInfo.UserID, false);

                //Add the value
                switch (formattedDisplaySeting)
                {
                    case “Display Name:”:
                        cboStudentSelection.Items.Add(new ListItem(oUser.DisplayName, oUser.UserID.ToString()));
                        break;
                    case “First + Last”:
                        cboStudentSelection.Items.Add(new ListItem(oUser.FirstName + ‘ ‘ + oUser.LastName, oUser.UserID.ToString()));
                        break;
                    case “Email”:
                        cboStudentSelection.Items.Add(new ListItem(oUser.Email, oUser.UserID.ToString()));
                        break;
                    default:
                        cboStudentSelection.Items.Add(new ListItem(oUser.DisplayName, oUser.UserID.ToString()));
                        break;
                }

            }
        }
        #endregion

        #region Student Selection Changed Events
        /// <summary>
        /// Retreives the users gradebook when the index of the student selection has been changed
        /// </summary>
        /// <param name=”sender”></param>
        /// <param name=”e”></param>
        protected void cboStudentSelection_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Get the users gradebook
            List<GradebookInfo> oGradebook;
            CourseGradebookController oController = new CourseGradebookController();

            oGradebook = oController.GetUserGradebook(PortalId,
                                int.Parse(Settings[“ICG_CourseGradebook_AssociatedCourse”].ToString()),
                                int.Parse(cboStudentSelection.SelectedValue.ToString()));

            //Ensure that we have assignments
            if (oGradebook.Count > 0)
            {
                //Bind the detail
                dgrGradeDetail.DataSource = oGradebook;
                dgrGradeDetail.DataBind();

                //Grab this students overall grade and display
                UserCurrentGradeInfo oGradeInfo = oController.GetUserCurrentGrade(PortalId,
                                        int.Parse(Settings[“ICG_CourseGradebook_AssociatedCourse”].ToString()),
                                        int.Parse(cboStudentSelection.SelectedValue.ToString()));

                //If the user has a grade
                if (oGradeInfo.Exists)
                {
                    //Get the course info
                    CourseSettingInfo oInfo = oController.GetCourseSetting(int.Parse(Settings[“ICG_CourseGradebook_AssociatedCourse”].ToString()), this.PortalId);

                    //Setup the view of the summary grade information (Grab from localization files....)
                    StringBuilder myBuilder = new StringBuilder(GetLocalizedText(“lblOverallGradeInfo”));
                    myBuilder.Replace(“[RECEIVED]”, oGradeInfo.TotalPointsReceived.ToString());
                    myBuilder.Replace(“[POSSIBLE]”, oGradeInfo.TotalPointsPossible.ToString());
                    myBuilder.Replace(“[PERCENT]”, oGradeInfo.PercentReceived.ToString());
                    myBuilder.Replace(“[LETTERGRADE]”, oGradeInfo.CalculateLetterGrade(oInfo));
                    lblStudentOverallGrade.Text = myBuilder.ToString();
                    lblStudentOverallGrade.Visible = true;
                }
                else
                {
                    //Ensure previous value cleared and hidden
                    lblStudentOverallGrade.Text = “”;
                    lblStudentOverallGrade.Visible = false;
                }
            }
            else
            {
                //Hide panels
                pnlStudentSelection.Visible = false;
                pnlStudentsGradebook.Visible = false;

                //Display module message
                DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, GetLocalizedText(“NoAssignments”), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning);
            }
        }
        #endregion

        #region Data Grid Events
        /// <summary>
        /// Binds records to the row
        /// </summary>
        /// <remarks>We are handling this method to ensure that no number is display if not graded!</remarks>
        /// <param name=”sender”></param>
        /// <param name=”e”></param>
        protected void dgrGradeDetail_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            //Only for item and alt item
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //Get the data item
                GradebookInfo oInfo = (GradebookInfo)e.Item.DataItem;

                //Get the template controls needed
                Label lblScore = (Label)e.Item.FindControl(“lblScoreReceived”);
                Label lblPercent = (Label)e.Item.FindControl(“lblPercent”);
                Label lblDateGraded = (Label)e.Item.FindControl(“lblDateGraded”);

                //Find out if it has been graded
                if (oInfo.ScoreReceived >= 0)
                {
                    //Place values in the fields
                    lblScore.Text = oInfo.ScoreReceived.ToString();
                    lblPercent.Text = oInfo.PercentReceived;
                    lblDateGraded.Text = oInfo.DateGraded.ToShortDateString();
                }
                else
                {
                    //No Score
                    lblScore.Text = “-”;
                    lblPercent.Text = “-”;
                    lblDateGraded.Text = “-”;
                }
            }
        }

        /// <summary>
        /// Responds to the user clicking the “Edit Score” button on the grid
        /// </summary>
        /// <param name=”source”></param>
        /// <param name=”e”></param>
        protected void dgrGradeDetail_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case “EditScore”:
                    //Move over the needed information
                    lblAssignmetnNameDisplay.Text = e.Item.Cells[0].Text;
                    lblPointsPossibleDisplay.Text = e.Item.Cells[2].Text;
                    lblStudentGradeId.Text = e.Item.Cells[4].Text;
                    lblAssignmentId.Text = e.Item.Cells[3].Text;

                    //Determine if we have a grade
                    if (int.Parse(lblStudentGradeId.Text) > 0)
                    {
                        //Get the grade info
                        CourseGradebookController oController = new CourseGradebookController();
                        UserAssignmentInfo oInfo = oController.GetUserAssignment(int.Parse(lblStudentGradeId.Text));

                        //Load the values
                        txtScoreReceived.Text = oInfo.ScoreReceived.ToString();
                        txtComment.Text = oInfo.Comment.Replace(“<br/>”, System.Environment.NewLine);

                        //Ensure that delete is available
                        btnDelete.Enabled = true;
                    }
                    else
                    {
                        //No grade, disable delete
                        btnDelete.Enabled = false;
                    }

                    //Disable user selection
                    cboStudentSelection.Enabled = false;
                    pnlStudentsGradebook.Visible = false;
                    pnlEditUserGrade.Visible = true;
                    break;
            }
        }
        #endregion

        #region Button Events
        //Resets the display
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            lblStudentGradeId.Text = “”;
            txtScoreReceived.Text = “”;
            txtComment.Text = “”;

            //Reset panels
            pnlEditUserGrade.Visible = false;
            pnlStudentsGradebook.Visible = true;

            //Re-enable student selection
            cboStudentSelection.Enabled = true;
        }
        /// <summary>
        /// Saves the informaton
        /// </summary>
        /// <param name=”sender”></param>
        /// <param name=”e”></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //Create the object for storing
            UserAssignmentInfo oInfo = new UserAssignmentInfo();
            bool isUpdate = false;
            oInfo.UserId = int.Parse(cboStudentSelection.SelectedValue);
            oInfo.AssignmentId = int.Parse(lblAssignmentId.Text);
            oInfo.DateEntered = DateTime.Now;
            oInfo.ScoreReceived = double.Parse(txtScoreReceived.Text);
            oInfo.UserAssignmentId = int.Parse(lblStudentGradeId.Text);
            oInfo.Comment = txtComment.Text.Replace(System.Environment.NewLine, “<br/>”); ;

            //Save object
            CourseGradebookController oController = new CourseGradebookController();
            if (oInfo.UserAssignmentId > 0)
            {
                oController.UpdateUserAssignment(oInfo);
                isUpdate = true;
            }
            else
            {
                oController.AddUserAssignment(oInfo);
            }

            //If e-mail notification enabled send student e-mail, as long as they have not opted out
            object emailStudents = Settings[“ICG_CourseGradebook_EmailStudent”];
            //First check if it is enabled
            if (emailStudents != null)
            {   
                //Now get the user optout value
                UserEmailOptOut oUserOptOut = oController.GetUserEmailOptOut(PortalId, oInfo.UserId);

                //If they have not opeted send it
                if(oUserOptOut == null || !oUserOptOut.OptOut)
                {
                    NotifyStudentOfGrading(oInfo.UserId, lblAssignmetnNameDisplay.Text, lblPointsPossibleDisplay.Text, txtScoreReceived.Text, txtComment.Text, isUpdate);
                }
            }

            //Rebind the grid
            cboStudentSelection_SelectedIndexChanged(sender, e);

            //Call cancel to end the edit
            btnCancel_Click(sender, e);
        }
        /// <summary>
        /// This method responds to the users request to delete a grade record.
        /// </summary>
        /// <remarks>No validation is needed as the JS confirmation is done first.</remarks>
        /// <param name=”sender”></param>
        /// <param name=”e”></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            //Delete the entry
            CourseGradebookController oController = new CourseGradebookController();
            oController.DeleteUserAssignment(int.Parse(lblStudentGradeId.Text));

            //Rebind the grid
            cboStudentSelection_SelectedIndexChanged(sender, e);

            //Call the cancel to end the edit operation
            btnCancel_Click(sender, e);
        }
        #endregion

        #region “Student Notification Methods”
        /// <summary>
        /// This method is used to send the notification to the student regarding the grading of their assignment
        /// this method is used to send the initial grading notification, a second method exists for modifications
        /// </summary>
        /// <param name=”studentId”>The id of the student to notify</param>
        /// <param name=”coursename”>The name of the course they are to be graded on</param>
        /// <param name=”assignmentName”>The name of the assignment they were graded on</param>
        /// <param name=”possiblePoints”>The points they could receive</param>
        /// <param name=”pointsGiven”>The points they were given</param>
        /// <param name=”isUpdate”>A boolean indicator showing if it is an udpated grade</param>
        public void NotifyStudentOfGrading(int studentId, string assignmentName, string possiblePoints, string pointsGiven, string comment, bool isUpdate)
        {
            //Load the SMTP Settings for the host
            string authType = DotNetNuke.Entities.Host.HostSettings.GetHostSetting(“SMTPAuthentication”);
            string SMTPServer = DotNetNuke.Entities.Host.HostSettings.GetHostSetting(“SMTPServer”);
            string SMTPUsername = DotNetNuke.Entities.Host.HostSettings.GetHostSetting(“SMTPUsername”);
            string SMTPPassword = DotNetNuke.Entities.Host.HostSettings.GetHostSetting(“SMTPPassword”);

            //Get the student info and instructor info
            DotNetNuke.Entities.Users.UserInfo oStudent = DotNetNuke.Entities.Users.UserController.GetUser(this.PortalId, studentId, false);
            DotNetNuke.Entities.Users.UserInfo oInstructor = DotNetNuke.Entities.Users.UserController.GetUser(this.PortalId, UserId, false);
         
            //Get the course info
            CourseGradebookController oCourseController = new CourseGradebookController();
            CourseSettingInfo oCourseSettings = oCourseController.GetCourseSetting(int.Parse(Settings[“ICG_CourseGradebook_AssociatedCourse”].ToString()), PortalId);

            //Get the localized strings
            string emailSubject;
            StringBuilder emailBody;
            if (isUpdate)
            {
                emailSubject = GetLocalizedText(“GradeNotificationUpdatedSubject”);
                emailBody = new StringBuilder(GetLocalizedText(“GradeNotificationUpdatedBody”));
            }
            else
            {
                emailSubject = GetLocalizedText(“GradeNotificationNewSubject”);
                emailBody = new StringBuilder(GetLocalizedText(“GradeNotificationNewBody”));
            }

            //Replace the tokens in the body/subject
            emailSubject = emailSubject.Replace(“[COURSE]”, oCourseSettings.CourseDisplayName);
            emailBody.Replace(“[STUDENT]”, oStudent.FirstName + “ “ + oStudent.LastName);
            emailBody.Replace(“[COURSE]”, oCourseSettings.CourseDisplayName);
            emailBody.Replace(“[ASSIGNMENT]”, assignmentName);
            emailBody.Replace(“[POINTSPOSS]”, possiblePoints);
            emailBody.Replace(“[POINTSREC]”, pointsGiven);
            emailBody.Replace(“[ENTRYBY]”, oInstructor.FirstName + “ “ + oInstructor.LastName);
            emailBody.Replace(“[COMMENT]”, comment.Replace(System.Environment.NewLine, “<br/>”));

            //Send the e-mail
            try
            {
                DotNetNuke.Services.Mail.Mail.SendMail(oInstructor.Email, oStudent.Email, “”, emailSubject, emailBody.ToString(), “”,”HTML”, SMTPServer, authType, SMTPUsername, SMTPPassword);
            }
            catch (Exception ex)
            {
                //Supress errors, with basic warning
                DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, GetLocalizedText(“EmailError”).Replace(“[ERROR}”, ex.Message), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning);
            }
        }
        #endregion

        #region IActionable Members
        public DotNetNuke.Entities.Modules.Actions.ModuleActionCollection ModuleActions
        {
            get
            {
                //Retun to module link!
                ModuleActionCollection actions = new ModuleActionCollection();
                actions.Add(GetNextActionID(), Localization.GetString(“ReturnToGradebook”, this.LocalResourceFile), ModuleActionType.EditContent,
                    “”, “”, DotNetNuke.Common.Globals.NavigateURL(TabId), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);
                return actions;
            }
        }
        #endregion


    }
}

Open in new window

ScreenShots.pdf
Mark01Asked:
Who is Participating?
 
Alfred A.Commented:
It seems to be being populated at

private void BindStudentsToGrid(System.Collections.ArrayList oList)

specific location:

//Add the value
                switch (formattedDisplaySeting)
                {
                    case “Display Name:”:
                        cboStudentSelection.Items.Add(new ListItem(oUser.DisplayName, oUser.UserID.ToString()));
                        break;
                    case “First + Last”:
                        cboStudentSelection.Items.Add(new ListItem(oUser.FirstName + ‘ ‘ + oUser.LastName, oUser.UserID.ToString()));
                        break;
                    case “Email”:
                        cboStudentSelection.Items.Add(new ListItem(oUser.Email, oUser.UserID.ToString()));
                        break;
                    default:
                        cboStudentSelection.Items.Add(new ListItem(oUser.DisplayName, oUser.UserID.ToString()));
                        break;
                }

0
 
Mark01Author Commented:
Hi Alfred1,

Thank you for the quick response.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.