none
In ASP.NET how to fetch the values from the html table . RRS feed

  • Question

  • Hi am struggling to save values from html table. i fetched HTML table which is required to me but am unable to save the values to database using stored procedure. Please Help me out.

    This is the code in .CS file am using to create html table. There are 7 table done in HTML.

    Now i need 2nd table. That is Done with this code.

     protected string preparesecgrid()
            {

                string strHtmlthead = @"<tr style='color: #ccccff; background-color: #1C5E55; font-weight: bold;'><th align='center' colspan='1' style='color: white;'>Sl#</th><th align='center' colspan='1' style='color: white;'>HRMSID</th><th align='center' style='color: white' width='300px';>EMP   NAME</th> <th align='center' style='color: white;'>Role</th><th align='center' style='color: white;'>Current Score</th>";
                string strHtmlcore = @"<tr style='color: #ccccff; background-color: #1C5E55; font-weight: bold;'>";
                string strHtmlcoreend = @"</tr>";
                string strHtmlpreend = @"</tr>";
                string strHtmltheadend = @"</tr>";
                string strHtmltbody = @"<tbody id='T2'><tr style='color: #ccccff; background-color: #1C5E55; font-weight: bold;'>";

                strHtmlthead += GetTHWithSpan() + strHtmltheadend;

                strHtmltbody += strHtmlpreend;

                int SNo = 0;
                foreach (DataRow row in dtTitle.Rows)
                {
                    strHtmltbody += "<tr style=\"color: #000000; background-color: White;\">";
                    string innerTd = GetcsNit(row[0].ToString(), row[1].ToString(), row[2].ToString());
                    strHtmltbody += "<td>" + (++SNo) + "</td>" + "<td>" + row[0].ToString() + "</td>" + "<td>" + row[1].ToString() + "</td>" + "<td>" + row[2].ToString() + "</td><td>" + CurrentScore + "</td>" + innerTd;
                    strHtmltbody += strHtmltheadend;
                }

                return strHtmlthead + strHtmlcore + strHtmlcoreend + strHtmltbody;

            }

            protected int GetSelectVal(string comp, string Role)
            {
                DataTable dt = SaveValues;
                DataRow dr = dt.AsEnumerable().ToList().Find(d => d[4].Equals(Role) && d[3].Equals(comp));
                //Cal Target Score
                if (dr != null)
                {
                    return Convert.ToInt32(dr.ItemArray[5].ToString());
                }
                return 0;
            }

            protected void GetValuesToSelectDDL()
            {
                foreach (DataRow row in dtmatrix.Rows)
                {
                    foreach (DataRow inRow in dtskill.Rows)
                    {
                        Getvalue(row[0].ToString(), inRow[0].ToString());
                    }
                }

            }

            // Calculate Current Score value

            protected string GetcsNit(string HRMSID, string EMPNAME, string Role)
            {
                string phsass1 = "Mid Year";
                string phsass2 = "End Year";

                if (Session["Page1Value"] != null)
                {
                    lbldisp.Text = Session["Page1Value"].ToString();
                }
                lblbu.Text = Convert.ToString(Request.QueryString["sbu"]);
                lblvs.Text = Convert.ToString(Request.QueryString["vs"]);
                lblyear.Text = Convert.ToString(Request.QueryString["yr"]);

                string sbu = Convert.ToString(lblbu.Text);
                string vs = Convert.ToString(lblvs.Text);
                string yearr = Convert.ToString(lblyear.Text);
                string disp = Convert.ToString(lbldisp.Text);
                string hrms = HRMSID;
                string name = EMPNAME;
                string ph1 = phsass1;
                string ph2 = phsass2;

                string strTD = string.Empty;
                CalCurrentScore = new List<MyCurrentScore>();
                CalTargetScore = new List<MyTargetScore>();
                // string role = dsmatrix.Tables[0].Rows[0].ItemArray[0].ToString();
                for (int i = 0; i < Colspan; i++)
                {
                    //Call SP To Get Values of Current Score and Indvidual Target
                    string comp = dsskill.Tables[0].Rows[i].ItemArray[0].ToString();
                    string role = dsmatrix.Tables[0].Rows[i].ItemArray[0].ToString();
                    string cc = comp;
                    objBOL = new ADT_BOL();
                    objBLL = new ADT_BLL();

                    dsassment = new DataSet();
                    dtassment = new DataTable();

                    if (Session["Page1Value"] != null)
                    {
                        lbldisp.Text = Session["Page1Value"].ToString();
                    }
                    lblbu.Text = Convert.ToString(Request.QueryString["sbu"]);
                    lblvs.Text = Convert.ToString(Request.QueryString["vs"]);
                    lblyear.Text = Convert.ToString(Request.QueryString["yr"]);

                    objBOL.OpertaionID = 1;
                    objBOL.SBU = Convert.ToString(lblbu.Text);
                    objBOL.Value_Stream = Convert.ToString(lblvs.Text);
                    objBOL.Discipline = Convert.ToString(lbldisp.Text);
                    objBOL.DateofAssessmentcs = Convert.ToString(lblyear.Text);
                    objBOL.HRMS_ID = HRMSID;
                    objBOL.Name = EMPNAME;
                    objBOL.Competency_Details = comp;
                    objBOL.PhaseofAssessment = phsass1;

                    int curscore = 0;
                    string stritt = string.Empty;

                    if (sbu.Equals(lblbu.Text) && vs.Equals(lblvs.Text) && disp.Equals(lbldisp.Text) && yearr.Equals(lblyear.Text) && hrms.Equals(HRMSID) && name.Equals(EMPNAME) && ph1.Equals(phsass1))
                    {
                        curscore = objBLL.CompetencyAssessmentDetailsCs_IUDS(objBOL).Tables[0].Rows.Count <= 0 ? 0 : Convert.ToInt32(objBLL.CompetencyAssessmentDetailsCs_IUDS(objBOL).Tables[0].Rows[0].ItemArray[0]);
                    }
                    //do
                    //{
                    int yr = Convert.ToInt32(lblyear.Text) - (1);
                    string y = Convert.ToString(yr);
                    if (curscore == 0)
                    {
                        if (sbu.Equals(lblbu.Text) && vs.Equals(lblvs.Text) && disp.Equals(lbldisp.Text) && hrms.Equals(HRMSID) && name.Equals(EMPNAME))
                        {
                            objBOL.DateofAssessmentcs = Convert.ToString(yr);
                            objBOL.PhaseofAssessment = ph1;
                            curscore = objBLL.CompetencyAssessmentDetailsCs_IUDS(objBOL).Tables[0].Rows.Count <= 0 ? 0 : Convert.ToInt32(objBLL.CompetencyAssessmentDetailsCs_IUDS(objBOL).Tables[0].Rows[0].ItemArray[0]);
                        }
                        if (curscore == 0)
                        {
                            objBOL.DateofAssessmentcs = Convert.ToString(yr);
                            objBOL.PhaseofAssessment = ph2;
                            curscore = objBLL.CompetencyAssessmentDetailsCs_IUDS(objBOL).Tables[0].Rows.Count <= 0 ? 0 : Convert.ToInt32(objBLL.CompetencyAssessmentDetailsCs_IUDS(objBOL).Tables[0].Rows[0].ItemArray[0]);
                        }

                    }

                    dd = GetDropDown(comp, Role);
                    int selval = GetSelectVal(comp, Role);
                    SaveSecValues.Rows.Add(sbu, vs, disp, yearr, hrms, name, curscore, dd, comp, role);
                    strTD += "<td>&nbsp;" + curscore + "</td><td>&nbsp;" + dd + "</td>";
                    // savesbu(sbu,vs,discipline,yearr,hrms,name,curscore,dd,comp,role);
                    CalCurrentScore.Add(new MyCurrentScore { Comp = comp, CS = curscore });
                    CalTargetScore.Add(new MyTargetScore { Comp = comp, TS = selval });


                }
                lstCS.Add(CalCurrentScore);
                lstTS.Add(CalTargetScore);
                return strTD;
            }

    Client Side:

    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function () {

                function OnSucceeded() {
                    alert("Saved Successfully..");
                }

                function OnFailed(error) {
                    alert(error.get_message());
                }

                $("#GHTML").click(function () {
                    PageMethods.GetHTML($("#T2")[0].innerHTML, OnSucceeded, OnFailed);
                });
            });
        </script>

    Server Side:

     [WebMethod]
            public static void GetHTML(object Html)
            {

             }

    In Html am getting the result as td tr and all. how to fetch one by one in that?

    That am not getting please help out.

    Any one please reply to this any one. i need it urgently.

    Thanks

    Pradeep



    Monday, August 12, 2013 7:16 AM