Ajath Sanjeev

Ajath Sanjeev

  • NA
  • 1
  • 1.3k

Can't edit Exam Names

May 6 2013 3:56 AM
dear frnds,
            
             pls help me.... its vry urgnt.... i can't edit the exam names whn i click the submit button... pls help me frnds .... below ones r ma codings


_______________________________________________________________________________________________________________________

<asp:Content ID="Content2" ContentPlaceHolderID="PageContentMain" runat="server">
    <table width="100%" cellpadding="5" cellspacing="0" border="0">
        <tr>
            <td>
                <div class="clean-gray">
                <table width="100%" cellpadding="2" cellspacing="2" border="0">
                    <tr>
                        <td>
                            Course Name
                        </td>
                        <td>
                            <asp:DropDownList runat="server" ID="ddlCourse" Width="250px" CssClass="cbox" 
                                onselectedindexchanged="ddlCourse_SelectedIndexChanged" AutoPostBack="true">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Year / Semester
                        </td>
                        <td>
                            <asp:DropDownList runat="server" ID="ddlYearSemester" Width="250px" CssClass="cbox">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    
                    <tr>
                        <td>
                            Batch
                        </td>
                        <td>
                            <asp:DropDownList runat="server" ID="ddlbatch" Width="250px" CssClass="cbox" >
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td width="30%">
                            Exam Code
                        </td>
                        <td><asp:HiddenField runat="server" ID="hdnExamId" Value="0" />
                            <asp:HiddenField runat="server" ID="hdnCurriculamId" Value="0" />
                            <asp:TextBox runat="server" ID="txtExamCode" Width="100" CssClass="tbox" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Exam Name
                        </td>
                        <td>
                            
                            <asp:TextBox runat="server" ID="txtExamName"  Width="217px" CssClass="tbox"/>   
                            &nbsp; <asp:LinkButton runat="server" ID="btnRetrivePapers" onclick="btnRetrivePapers_Click">Retrive Papers from Curriculam</asp:LinkButton>
                        </td>
                    </tr>
                </table>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%" cellpadding="2" cellspacing="2" border="0">
                    <tr>
                        <td width="60%">
                            <table class="grid" width="100%">
                                <asp:Repeater ID="rptrPapers" runat="server" 
                                   OnItemDataBound="rptrPapers_ItemDataBound" >
                                    <HeaderTemplate>
                                        <thead>
                                        <tr>
                                            <th>
                                                Sl No
                                            </th>
                                            <th>
                                                Paper Name
                                            </th>
                                            <th>
                                                Date of Exam
                                            </th>
                                            <th>
                                                External Maximum Mark
                                            </th>
                                            <th>
                                                External Pass Mark
                                            </th>
                                            <th>
                                              Internal Max Mark
                                            </th>
                                            <th>
                                              Internal Pass Mark
                                            </th>
                                             <th>
                                              Exam Duration
                                            </th>
                                      </tr>
                                        </thead>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <tr class="row-a">
                                            <td>
                                                <asp:CheckBox runat="server" ID="chkPaper" CssClass="tbox"/>
                                                <asp:HiddenField runat="server" ID="hdnPaperId" />
                                            </td>
                                            <td>
                                                <asp:Label runat="server" ID="lblPaperName" Width="200px" MaxLength="350" />
                                            </td>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtDate" Width="100px" MaxLength="15" CssClass="tbox"/>  
                                            </td>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtExtMaxMark" Width="100px" MaxLength="3" CssClass="tbox"/>  
                                            </td>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtExtPassMark" Width="100px" MaxLength="5" CssClass="tbox"/>  
                                            </td>
                                             <td>
                                                <asp:TextBox runat="server" ID="txtIntMaxMark" Width="100px" MaxLength="3" CssClass="tbox"/>  
                                            </td>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtIntPassMark" Width="100px" MaxLength="5" CssClass="tbox"/>  
                                            </td>
                                             <td>
                                                <asp:TextBox runat="server" ID="txtExamDuration" Width="100px" MaxLength="35" CssClass="tbox"/>  
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>&nbsp;</td>
                                        </tr>
                                    </ItemTemplate>
                                    <AlternatingItemTemplate>
                                         <tr class="row-b">
                                            <td>
                                                <asp:CheckBox runat="server" ID="chkPaper" CssClass="tbox"/>
                                                <asp:HiddenField runat="server" ID="hdnPaperId" />
                                            </td>
                                            <td>
                                                <asp:Label runat="server" ID="lblPaperName" Width="200px" MaxLength="350" />
                                            </td>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtDate" Width="100px" MaxLength="15" CssClass="tbox"/>  
                                            </td>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtExtMaxMark" Width="100px" MaxLength="3" CssClass="tbox"/>  
                                            </td>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtExtPassMark" Width="100px" MaxLength="5" CssClass="tbox"/>  
                                            </td>
                                             <td>
                                                <asp:TextBox runat="server" ID="txtIntMaxMark" Width="100px" MaxLength="3" CssClass="tbox"/>  
                                            </td>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtIntPassMark" Width="100px" MaxLength="5" CssClass="tbox"/>  
                                            </td>
                                             <td>
                                                <asp:TextBox runat="server" ID="txtExamDuration" Width="100px" MaxLength="35" CssClass="tbox"/>  
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>&nbsp;</td>
                                        </tr>
                                    </AlternatingItemTemplate>
                                </asp:Repeater>
                                <tr>
                                    <td colspan="3">
                                        &nbsp;<asp:LinkButton runat="server" ID="lnkRemovePaper" Text="Remove Selected" OnClick="lnkRemovePaper_Click" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
             </td>
       </tr>
       <tr>
            <td align="center">  
                <asp:Button runat="server" CssClass="button" ID="btnSubmit" Text="Submit" 
                    onclick="btnSubmit_Click" />&nbsp;
                <asp:Button runat="server" CssClass="button" ID="btnReset" Text="Reset" PostBackUrl="~/ListExam.aspx" />
            </td>
        </tr>
    </table>
</asp:Content>



__________________________________________________________________________________________________________________________


 public partial class EditExam : BasePage
    {
        ExaminationBl bl = new ExaminationBl();
        LookUpBl blLookup = new LookUpBl();
        StudentBl studBl=new StudentBl();

        int courseId=0;
        
        private void PopulateSemesters()
        {
            courseId = Convert.ToInt32(ddlCourse.SelectedValue);
            hdnCurriculamId.Value = Convert.ToString(bl.GetCurriculamId(courseId));
            if(courseId > 0 ) Utils.UIHelper.LoadDropDownList(ref ddlYearSemester, blLookup.GetCourseSemestersLookups(courseId));
        }

        private void InitPageObjects()
        {
            UIHelper.LoadDropDownList(ref ddlCourse, blLookup.GetCourseLookups());
            PopulateSemesters();
            if (Request.QueryString["Id"] != null)
            {
                int Id = Convert.ToInt32(Request.QueryString["Id"].ToString());
                if (Id > 0)
                {
                    Examination exam = bl.GetExamDeatils(Id);
                    this.SetDataObjects(exam);
                    btnReset.Text = "Back";
                    btnReset.PostBackUrl = "ListExam.aspx";
                }
            }
            else
            {
                btnReset.Attributes.Add("onclick", "return ClealFields();");
            }
        }

        private void SetDataObjects(Examination exam)
        {
            hdnExamId.Value = exam.ID.ToString();
            hdnCurriculamId.Value = exam.CurriculamId.ToString();
            txtExamCode.Text = exam.Code;
            txtExamName.Text = exam.Name;
            int courseId = exam.Course.Id;
            int batchID = exam.Batch.Id;
            Utils.UIHelper.LoadDropDownList(ref ddlbatch, blLookup.GetBatchLookups(courseId));
            Utils.UIHelper.LoadDropDownList(ref ddlYearSemester, blLookup.GetCourseSemestersLookups(courseId));

            Utils.UIHelper.SelectDropDownListItem(ref ddlCourse, courseId.ToString());
            Utils.UIHelper.SelectDropDownListItem(ref ddlbatch, batchID.ToString());
            Utils.UIHelper.SelectDropDownListItem(ref ddlYearSemester, exam.YearSequence.ToString());
            
            PopulateExamPapers(exam.Papers);

        }

        private void Page_Init(object sender, System.EventArgs e)
        {
            masterPage = (SecurePage)Page.Master;
            masterPage.SetPageTitle("Examinations Entry/Update", "Create Update Examinations.");
            if (!Page.IsPostBack)
            {
                masterPage.PopulateSubMenu(5);
                this.InitPageObjects();
            }
        }

        private void PopulateExamPapers(ExamPapers list)
        {
            rptrPapers.DataSource = list;
            rptrPapers.DataBind();
        }

        private ExamPapers GetExamPapers(bool bDelete = false)
        {
            //List<ExamPaper> list = new List<ExamPaper>();
            ExamPapers list = new ExamPapers();
            foreach (RepeaterItem rptItem in rptrPapers.Items)
            {
                ExamPaper item = new ExamPaper();
                HiddenField hdnPaperId = rptItem.FindControl("hdnPaperId") as HiddenField;
                Label lblPaperName = rptItem.FindControl("lblPaperName") as Label;
                
                CheckBox chkPaper = rptItem.FindControl("chkPaper") as CheckBox;
                TextBox txtDate = rptItem.FindControl("txtDate") as TextBox;
                TextBox txtExtMaxMark = rptItem.FindControl("txtExtMaxMark") as TextBox;
                TextBox txtExtPassMark = rptItem.FindControl("txtExtPassMark") as TextBox;
                TextBox txtIntMaxMark = rptItem.FindControl("txtIntMaxMark") as TextBox;      ///Edited by pritam
                TextBox txtIntPassMark = rptItem.FindControl("txtIntPassMark") as TextBox;
                TextBox txtExamDuration = rptItem.FindControl("txtExamDuration") as TextBox;    ///Edited by pritam

                if (bDelete && chkPaper.Checked) continue; // skip adding the row

                item.ExamDate = Convert.ToDateTime(txtDate.Text);
                item.ExtMaximumMark = Convert.ToDecimal(txtExtMaxMark.Text);
                item.ExtPassMark = Convert.ToDecimal(txtExtPassMark.Text);
                item.InternalMaxMark = Convert.ToDecimal(txtIntMaxMark.Text);
                item.InternalPassMark = Convert.ToDecimal(txtIntPassMark.Text);
                item.TotalMaxMark = Convert.ToDecimal(item.ExtMaximumMark + item.InternalMaxMark);
                item.TotalPassMark = Convert.ToDecimal(item.ExtPassMark + item.InternalPassMark);
                item.ExamDuration = txtExamDuration.Text;                                          ////Edited by pritam

                item.Paper = new LookUp();
                item.Paper.Id = Convert.ToInt32(hdnPaperId.Value);
                item.Paper.Name = lblPaperName.Text;
                list.Add(item);
            }
            return list;
        }

        protected void rptrPapers_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ExamPaper item = e.Item.DataItem as ExamPaper;
                HiddenField hdnPaperId = e.Item.FindControl("hdnPaperId") as HiddenField;
                Label lblPaperName = e.Item.FindControl("lblPaperName") as Label;
                
                CheckBox chkPaper = e.Item.FindControl("chkPaper") as CheckBox;
                TextBox txtDate = e.Item.FindControl("txtDate") as TextBox;
                TextBox txtExtMaxMark = e.Item.FindControl("txtExtMaxMark") as TextBox;
                TextBox txtExtPassMark = e.Item.FindControl("txtExtPassMark") as TextBox;
                TextBox txtIntMaxMark = e.Item.FindControl("txtIntMaxMark") as TextBox;
                TextBox txtIntPassMark = e.Item.FindControl("txtIntPassMark") as TextBox;
                TextBox txtExamDuration = e.Item.FindControl("txtExamDuration") as TextBox;     ////Edited by pritam

                txtDate.Text = item.ExamDate.ToShortDateString();
                txtExtMaxMark.Text = item.ExtMaximumMark.ToString();
                txtExtPassMark.Text = item.ExtPassMark.ToString(); 
                txtIntMaxMark.Text = item.InternalMaxMark.ToString();
                txtIntPassMark.Text = item.InternalPassMark.ToString();
                txtExamDuration.Text = item.ExamDuration.ToString();       ////Edited by pritam

                hdnPaperId.Value = item.Paper.Id.ToString();
                lblPaperName.Text = item.Paper.Name;
                 
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void lnkRemovePaper_Click(object sender, EventArgs e)
        {
            ExamPapers list = this.GetExamPapers(true);
            PopulateExamPapers(list);
        }

        private Examination GetDataObjects()
        {
            Examination exam = new Examination();
           // exam.Papers = new ExamPapers();  ///Edited by pritam
            exam.Id = Convert.ToInt32(hdnExamId.Value);
            exam.ID = exam.Id;
            exam.Code = txtExamCode.Text;
            exam.Name = txtExamName.Text;
            exam.CurriculamId = Convert.ToInt32(hdnCurriculamId.Value);
            exam.CurriculumID = exam.CurriculamId;
            exam.Course = new LookUp();
            exam.Course.Id = Convert.ToInt32(ddlCourse.SelectedValue);
            exam.Batch = new LookUp();
            exam.Batch.Id = Convert.ToInt32(ddlbatch.SelectedValue);
            exam.YearSequence = Convert.ToInt32(ddlYearSemester.SelectedValue);
            exam.Papers = this.GetExamPapers(); 
            return exam;
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (ddlbatch.SelectedIndex > 0)
                {
                    Examination item = this.GetDataObjects();
                    int Id = bl.SavExamDeatils(item);
                    if (Id > 0)
                    {
                        Response.Redirect("ViewExam.aspx?Id=" + Id.ToString()); ////Id.ToString());
                    }
                }
                else
                {
                    masterPage.SetMessage("Please select a Batch from the Dropdown List to proceed.");
                }
            }
            catch (Exception ex)
            {
                masterPage.SetMessage(ex.Message);
            }
        }
        
        protected void btnRetrivePapers_Click(object sender, EventArgs e)
        {
            int courseId = Convert.ToInt32(ddlCourse.SelectedValue);
            int yearId = Convert.ToInt32(ddlYearSemester.SelectedValue);
            if (courseId > 0) PopulateExamPapers(bl.GetExamPapers(courseId, yearId));
        }

        protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlCourse.SelectedIndex > 0)
            {
                courseId = Convert.ToInt32(ddlCourse.SelectedValue);
                //this.PopulateSemesters();
                Utils.UIHelper.LoadDropDownList(ref ddlbatch, blLookup.GetBatchLookups(courseId));
                Utils.UIHelper.LoadDropDownList(ref ddlYearSemester, blLookup.GetCourseSemestersLookups(courseId));
            }
            else
            {
                masterPage.SetMessage("Please select a Course from the Dropdown List to proceed.");
            }
        }

    }
}

.....................................................................................................................................................................................................................................................