Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
              
            }

         studtid  = Request .QueryString ["studentid"];
         studtname = Request.QueryString["studname"];
            try
            {
                lblcoursedetref.Visible = false;
                param = Request.QueryString["studentid"];
                studentname = Request.QueryString["studname"];
                lblstudenname.Text = studentname;
                if (!IsPostBack)
                {

                    if (param != null)
                    {
                        objBS.open();
                        SqlCommand cmd = new SqlCommand("SP_T_COURSE_DETAILS_SELECT", objBS.conn);
                        lblstudenid.Text = param;

                        cmd.CommandType = CommandType.StoredProcedure;
                        //cmd.Parameters.Add("P_COURSE_DET_REF", SqlDbType.Int).Value = Convert.ToDecimal(studentid1);
                        cmd.Parameters.Add("@COURSE_DET_REF", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@STUDENT_ROLL_NO", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@STUDENT_ID", SqlDbType.Int).Value = Convert.ToDecimal(param);

                        cmd.Parameters.Add("@COURSE_ID", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@SEMESTER", SqlDbType.VarChar, 20).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@SUBJECT_ID", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@START_YEAR", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@END_YEAR", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@COURSE_DETAILS_STATUS", SqlDbType.VarChar, 1).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@LAST_UPDATED_DT", SqlDbType.DateTime).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@LAST_UPDATED_BY", SqlDbType.VarChar, 10).Direction = ParameterDirection.Output;
                        cmd.ExecuteNonQuery();
                        lblstudenid.Text = (cmd.Parameters["@STUDENT_ID"].Value).ToString();
                        txtsturollno.Text = (cmd.Parameters["@STUDENT_ROLL_NO"].Value).ToString();
                        lblcoursedetref.Text = (cmd.Parameters["@COURSE_DET_REF"].Value).ToString();


                        ddlcoursename.Text = (cmd.Parameters["@COURSE_ID"].Value).ToString();
                        ddlsemester.Text = (cmd.Parameters["@SEMESTER"].Value).ToString();
                        ddlsubjectname.Text = (cmd.Parameters["@SUBJECT_ID"].Value).ToString();
                        txtstartdate.Text = (cmd.Parameters["@START_YEAR"].Value).ToString();
                        txtenddate.Text = (cmd.Parameters["@END_YEAR"].Value).ToString();
                        ddlstatusu.SelectedValue = (cmd.Parameters["@COURSE_DETAILS_STATUS"].Value).ToString();

                        hypstudent.NavigateUrl = "~/studentinf.aspx?studentid=" + param + "&studname=" + studentname;
                        hypattendance.NavigateUrl = "~/sattendance.aspx?studentid=" + param + "&studname=" + studentname;
                        hypfees.NavigateUrl = "~/sfees.aspx?studentid=" + param + "&studname=" + studentname;
                        hypresult.NavigateUrl = "~/sresult.aspx?studentid=" + param + "&studname=" + studentname;
                        hyptransfer.NavigateUrl = "~/stransfer.aspx?studentid=" + param + "&studname=" + studentname;
                    }

                    

                    else
                    {
                        lblstudenid.Text = studtid.ToString();
                        lblstudenname.Text = studtname.ToString();
                    }
                    if (param == null )
                    {
                        hypstudent.Visible = false;
                        hypattendance.Visible = false;
                        hypfees.Visible = false;
                        hypresult.Visible = false;
                        hyptransfer.Visible = false;
                      
                        butscoursesave.Visible = true;
                        butupdate.Visible = false;
                    }

                    if (lblcoursedetref.Text !="")
                    {
                        butupdate.Visible = true;
                        butscoursesave.Visible = false;
                    }
                    else if (lblcoursedetref.Text == "")
                    {
                        butscoursesave.Visible = true;
                        butupdate.Visible = false;
                    }


                }
                //BindCoursedropdown();

            }
            catch (Exception ex)
            {

                //// Response.Write(ex.ToString());
                if (lblcoursedetref.Text != "")
                {
                    butupdate.Visible = true;
                    butscoursesave.Visible = false;
                }
                else if (lblcoursedetref.Text == "")
                {
                    butscoursesave.Visible = true;
                    butupdate.Visible = false;

                }
                hypstudent.NavigateUrl = "~/studentinf.aspx?studentid=" + param + "&studname=" + studentname;
                hypattendance.NavigateUrl = "~/sattendance.aspx?studentid=" + param + "&studname=" + studentname;
                hypfees.NavigateUrl = "~/sfees.aspx?studentid=" + param + "&studname=" + studentname;
                hypresult.NavigateUrl = "~/sresult.aspx?studentid=" + param + "&studname=" + studentname;
                hyptransfer.NavigateUrl = "~/stransfer.aspx?studentid=" + param + "&studname=" + studentname;
            }
        }
Posted
Comments
Nivedita_Parihar 5-Jun-14 4:06am    
What is the issue in this?
Saral S Stalin 6-Jun-14 3:14am    
Assuming ddlcoursename is a dropdown list, below code is not right. You have to bind the drop down list with a dataset.

<pre lang="C#">ddlcoursename.Text = (cmd.Parameters["@COURSE_ID"].Value).ToString();</pre>

Is this a homework? Google it for working with dropdownlist.

1 solution

Change this line
C#
ddlcoursename.Text = (cmd.Parameters["@COURSE_ID"].Value).ToString();

with
C#
ddlcoursename.SelectedValue= (cmd.Parameters["@COURSE_ID"].Value).ToString();


Also make sure that you have filled the dropdownlist before this line of code. This is the most possible cause of the error you are getting.

In case this doesn't resolve the problem, let me know :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900