Learn As Much As You Can

Friday 15 March 2013

How to make the HTML table in C# (on the server side, values comes from the database)


 while (sqr.Read())
            {
                string partner_name = sqr.GetString(0);
                int partner_id = sqr.GetInt32(1);
                HtmlPartnerNameDiv += "<div id=" + partner_name + " class=tab_airline><a href=flights.html class=more_offers title=More Offers>More Offers" +
                                      "</a><div class=list-head><h2>" + partner_name + " Latest Fares </h2> </div><table class=home_partnerfares><thead><tr><th width=90 scope=col>" +
                                      "<strong>DESTINATIONS</strong></th><th width=113 scope=col ><strong>Travel dates </strong> </th><th width=70 scope=col><strong>Book by</strong></th>" +
                                      "<th width=38 scope=col><strong> Fare </strong></th><th width=40 scope=col><strong> More  </strong></th></tr></thead>";
                GetAllFaresByIdGridView(partner_id);
                HtmlPartnerNameDiv += HtmlTable;
            }



protected string GetAllFaresByIdGridView(int id)
    {
        string htmlStr = "";
        HtmlTable = "";
        try
        {
            using (SqlConnection conn = DataAccess.GetConnected())
            {
                SqlCommand cmd = new SqlCommand("GetAllFaresByID", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ID", id);
                cmd.Parameters.Add(new SqlParameter("@Error", SqlDbType.VarChar, 255));
                cmd.Parameters["@Error"].Direction = ParameterDirection.Output;
                cmd.Parameters.Add(new SqlParameter("@count", SqlDbType.VarChar, 255));
                cmd.Parameters["@count"].Direction = ParameterDirection.Output;
                SqlDataReader sqr = cmd.ExecuteReader();
                htmlStr += "<tbody>";
                while (sqr.Read())
                {
                    string Destination = sqr.GetString(0);
                    string Travel_From_Date = sqr.GetString(1);
                    string Travel_To_Date = sqr.GetString(2);
                    string Book_By = sqr.GetString(3);
                    int Fare = sqr.GetInt32(4);
                    htmlStr+= "<tr ><td>" + Destination + "</td>" +
                              "<td>" + Travel_From_Date + " - " + Travel_To_Date + "</td><td>" + Book_By + "</td><td class=price>&pound;" + Fare + "</td><td><a href=flights.html title=View Details>" +
                              "view &rsaquo; </a></td> </tr>";
                }
            }
        }
        catch (Exception ex)
        {
            //throw ex.Message;
        }
        htmlStr += "</tbody></table></div>";
        HtmlTable += htmlStr;
        return htmlStr;
    }

0 comments :

Post a Comment