private void LoadLevelsFromDatabase()
    {
        try
        {
            Result oResult = new Result();
            LevelBO oLevelBO = new LevelBO();

            List<Level> oListLevel = new List<Level>();

            oResult = oLevelBO.LoadAllLevels();

            if (oResult.ResultIsSuccess)
            {
                oListLevel = (List<Level>)oResult.ResultObject;

                drdnSelectQuestionLevel.Items.Clear();
                drdnSelectQuestionLevel.Items.Add(new ListItem("[Select One]", "[Select One]"));

                foreach (Level oLevelInList in oListLevel)
                {
                    drdnSelectQuestionLevel.Items.Add(new ListItem(oLevelInList.LevelName, oLevelInList.LevelID.ToString()));
                }
            }
            else
            {
                lbl_error.ForeColor = Color.Red;
                lbl_error.Text = oResult.ResultMessage;
            }
        }
        catch (Exception oEx)
        {

        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            Result oResult = new Result();

            LevelBO oLevelBO = new LevelBO();

            //Level oOldLevel = new Level();

            if (listLevels.Items.Count > 0)
            {
                if (listLevels.SelectedIndex >= 0)
                {
                    if (IsValidLevelName(txtLavelName.Text))
                    {
                        //oOldLevel = oListForDataList[listLevels.SelectedIndex];

                        oListForDataList[listLevels.SelectedIndex].LevelName = txtLavelName.Text;

                        if (IsValidLevelDescription(txtLevelDescription.Text))
                        {
                            oListForDataList[listLevels.SelectedIndex].LevelDescription = txtLevelDescription.Text.Replace("'", String.Empty);
                        }

                        oResult = oLevelBO.LevelUpdate(oListForDataList[listLevels.SelectedIndex]);

                        if (oResult.ResultIsSuccess)
                        {
                            LoadLevelsToDataList();

                            clearField();

                            lbl_error.ForeColor = Color.Green;
                            lbl_error.Text = oResult.ResultMessage;
                        }
                        else
                        {
                            lbl_error.ForeColor = Color.Red;
                            lbl_error.Text = oResult.ResultMessage;

                            LoadLevelsToDataList();
                        }
                    }
                    else
                    {
                        lbl_error.ForeColor = Color.Red;
                        lbl_error.Text = "',- is not Allowed. Level must not empty";
                    }
                }
                else
                {
                    lbl_error.ForeColor = Color.Red;
                    lbl_error.Text = "select a level.";
                }
            }
        }
        catch (Exception oEx)
        {

        }
    }
    protected void btn_delete_Click(object sender, EventArgs e)
    {
        try
        {
            Result oResult = new Result();

            LevelBO oLevelBO = new LevelBO();

            if (listLevels.Items.Count > 0)
            {
                if (listLevels.SelectedIndex >= 0)
                {
                    oResult = oLevelBO.Delete(oListForDataList[listLevels.SelectedIndex]);

                    if (oResult.ResultIsSuccess)
                    {
                        lbl_error.ForeColor = Color.Green;
                        lbl_error.Text = oResult.ResultMessage;

                        LoadLevelsToDataList();

                        clearField();
                    }
                    else
                    {
                        lbl_error.ForeColor = Color.Red;
                        lbl_error.Text = oResult.ResultMessage;
                    }
                }
                else
                {
                    lbl_error.ForeColor = Color.Red;
                    lbl_error.Text = "select a level.";
                }
            }
        }
        catch (Exception oEx)
        {

        }
    }
    private void LoadLevelsToDataList()
    {
        try
        {
            Result oResult = new Result();
            LevelBO oLevelBO = new LevelBO();

            oResult = oLevelBO.LoadAllLevels();

            listLevels.Items.Clear();

            if (oResult.ResultIsSuccess)
            {
                oListForDataList = (List<Level>)oResult.ResultObject;

                this.ViewState.Add(SessionManager.csStoreGridView, oListForDataList);

                //listLevels.DataSource = oListForDataList;
                //listLevels.DataBind();

                foreach (Level oLevelInList in oListForDataList)
                {
                    listLevels.Items.Add(new ListItem(oLevelInList.LevelName,oLevelInList.LevelName));
                }

            }
            else
            {
                lbl_error.ForeColor = Color.Red;
                lbl_error.Text = oResult.ResultMessage;
            }
        }
        catch (Exception oEx)
        {

        }
    }
    protected void btn_AddLevel_Click(object sender, EventArgs e)
    {
        try
        {
            Result oResult = new Result();
            Level oLevel = new Level();
            LevelBO oLevelBO = new LevelBO();

            if (IsValidLevelName(txtLavelName.Text))
            {
                oLevel.LevelID = Guid.NewGuid();
                oLevel.LevelName = txtLavelName.Text;

                if (IsValidLevelDescription(txtLevelDescription.Text))
                {
                    oLevel.LevelDescription = txtLevelDescription.Text.Replace("'", String.Empty);
                }

                oResult = oLevelBO.LevelEntry(oLevel);

                if (oResult.ResultIsSuccess)
                {
                    lbl_error.ForeColor = Color.Green;
                    lbl_error.Text = oResult.ResultMessage;

                    LoadLevelsToDataList();

                    clearField();
                }
                else
                {
                    lbl_error.ForeColor = Color.Red;
                    lbl_error.Text = oResult.ResultMessage;
                }
            }
            else
            {
                lbl_error.ForeColor = Color.Red;
                lbl_error.Text = "',- is not Allowed. Level must not empty";
            }
        }
        catch (Exception oEx)
        {

        }
    }