Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i generated a HTML table in my c# code and in this table i loaded data from sql server by program in button_click. My All Code is .....
protected void search_btn_Click(object sender, EventArgs e)
{
string htmlGenerator = string.Empty;
string[] bookID = new string[120];
XML
string[] ShelfNo = new string[120];
string[] BookName = new string[120];
string[] Writer = new string[120];
string[] Type = new string[120];
string[] Status = new string[120];
string[] bookvolum = new string[120];



SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["librarymanagment"].ToString());
SqlCommand cmd = new SqlCommand();



cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "Sp_SEARCHBOOK";
cmd.Parameters.Add("@Book_id", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@Shelf_number", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@Book_name", SqlDbType.NVarChar, 250).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@Writer_name", SqlDbType.NVarChar, 250).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@Number_of_volume", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@part_volume", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@Publications", SqlDbType.NVarChar, 250).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@Publications_place", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@Published_year", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@Edition", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@status", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
cmd.Parameters.Add("@Book_type", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();

cmd.Connection = con;
  con.Open();
   SqlDataReader reader = cmd.ExecuteReader();
   if (reader.HasRows)
   {
       int totalRecords = 0;
       while (reader.Read())
       {
           bookID[totalRecords] = reader["Book ID"].ToString();
           ShelfNo[totalRecords] = reader["Shelf No"].ToString();
           BookName[totalRecords] = reader["Book Name"].ToString();
           Writer[totalRecords] = reader["Writer"].ToString();
           Type[totalRecords] = reader["Type"].ToString();
           Status[totalRecords] = reader["Status"].ToString();
           bookvolum[totalRecords] = reader["Volume"].ToString();

           totalRecords = totalRecords + 1;

       }
       int rows2 = 0;
       htmlGenerator = "<table cellpadding='3' cellspacing='3' >";
       htmlGenerator += "<thead><tr style='background-color: #1C5E55;  color: #FFFFFF'><th style='width:50px'>Book ID</th><th style='width:170px'>Name</th><th style='width:50px'>Writer</th><th style='width:50px'>Shelf No</th><th style='width:30px'>Type</th><th style='width:30px'>Status</th></tr></thead>";
       for (int i = 0; i < totalRecords; i++)
       {

           if (i < totalRecords)
           {

               if(rows2<1)
               {
               htmlGenerator += "<tr style='background-color: #E3EAEB'>";
               htmlGenerator += "<td><a href='Issue_book.aspx?bid=" + bookID[i] + "&bname=" + BookName[i] + "&bvolum=" + bookvolum[i] + " '>" + bookID[i] + "</a></td>";
               htmlGenerator += "<td>" + BookName[i] + "</td>";
               htmlGenerator += "<td>" + Writer[i] + "</td>";
               htmlGenerator += "<td>" + ShelfNo[i] + "</td>";
               htmlGenerator += "<td>" + Type[i] + "</td>";
               htmlGenerator += "<td>" + Status[i] + "</td>";
               htmlGenerator += "</tr>";
                   rows2=1;
               }
               else
               {
                   htmlGenerator += "<tr style='background-color: #FFFFFF'>";
                   htmlGenerator += "<td><a href='Issue_book.aspx?bid=" + bookID[i] + "&bname="+BookName[i]+"&bvolum="+bookvolum[i]+" '>" + bookID[i] + "</a></td>";
                   htmlGenerator += "<td>" + BookName[i] + "</td>";
                   htmlGenerator += "<td>" + Writer[i] + "</td>";
                   htmlGenerator += "<td>" + ShelfNo[i] + "</td>";
                   htmlGenerator += "<td>" + Type[i] + "</td>";
                   htmlGenerator += "<td>" + Status[i] + "</td>";
                   htmlGenerator += "</tr>";
                   rows2 = 0;
               }

           }
       }
       htmlGenerator += "</table>";
       Label2.Text =  protected void search_btn_Click(object sender, EventArgs e)
        {
            string htmlGenerator = string.Empty;
            string[] bookID = new string[120];
            string[] ShelfNo = new string[120];
            string[] BookName = new string[120];
            string[] Writer = new string[120];
            string[] Type = new string[120];
            string[] Status = new string[120];
            string[] bookvolum = new string[120];



            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["librarymanagment"].ToString());
            SqlCommand cmd = new SqlCommand();
         
          
              
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.CommandText = "Sp_SEARCHBOOK";
            cmd.Parameters.Add("@Book_id", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@Shelf_number", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@Book_name", SqlDbType.NVarChar, 250).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@Writer_name", SqlDbType.NVarChar, 250).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@Number_of_volume", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@part_volume", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@Publications", SqlDbType.NVarChar, 250).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@Publications_place", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@Published_year", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@Edition", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@status", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();
            cmd.Parameters.Add("@Book_type", SqlDbType.NVarChar, 50).Value = search_TextBox.Text.Trim();

            cmd.Connection = con;
              con.Open();
               SqlDataReader reader = cmd.ExecuteReader();
               if (reader.HasRows)
               {
                   int totalRecords = 0;
                   while (reader.Read())
                   {
                       bookID[totalRecords] = reader["Book ID"].ToString();
                       ShelfNo[totalRecords] = reader["Shelf No"].ToString();
                       BookName[totalRecords] = reader["Book Name"].ToString();
                       Writer[totalRecords] = reader["Writer"].ToString();
                       Type[totalRecords] = reader["Type"].ToString();
                       Status[totalRecords] = reader["Status"].ToString();
                       bookvolum[totalRecords] = reader["Volume"].ToString();

                       totalRecords = totalRecords + 1;

                   }
                   int rows2 = 0;
                   htmlGenerator = "<table cellpadding="3" cellspacing="3">";
                   htmlGenerator += "<thead><tr style="background-color: #1C5E55;  color: #FFFFFF"><th style="width:50px">Book ID</th><th style="width:170px">Name</th><th style="width:50px">Writer</th><th style="width:50px">Shelf No</th><th style="width:30px">Type</th><th style="width:30px">Status</th></tr></thead>";
                   for (int i = 0; i < totalRecords; i++)
                   {
                      
                       if (i < totalRecords)
                       {
                           
                           if(rows2<1)
                           {
                           htmlGenerator += "<tr style="background-color: #E3EAEB">";
                           htmlGenerator += "<td><a href="Issue_book.aspx?bid=" + bookID[i] + "&bname=" + BookName[i] + "&bvolum=" + bookvolum[i] + " ">" + bookID[i] + "</a></td>";
                           htmlGenerator += "<td>" + BookName[i] + "</td>";
                           htmlGenerator += "<td>" + Writer[i] + "</td>";
                           htmlGenerator += "<td>" + ShelfNo[i] + "</td>";
                           htmlGenerator += "<td>" + Type[i] + "</td>";
                           htmlGenerator += "<td>" + Status[i] + "</td>";
                           htmlGenerator += "</tr>";
                               rows2=1;
                           }
                           else
                           {
                               htmlGenerator += "<tr style="background-color: #FFFFFF">";
                               htmlGenerator += "<td><a href="Issue_book.aspx?bid=" + bookID[i] + "&bname="+BookName[i]+"&bvolum="+bookvolum[i]+" ">" + bookID[i] + "</a></td>";
                               htmlGenerator += "<td>" + BookName[i] + "</td>";
                               htmlGenerator += "<td>" + Writer[i] + "</td>";
                               htmlGenerator += "<td>" + ShelfNo[i] + "</td>";
                               htmlGenerator += "<td>" + Type[i] + "</td>";
                               htmlGenerator += "<td>" + Status[i] + "</td>";
                               htmlGenerator += "</tr>";
                               rows2 = 0;
                           }
                          
                       }
                   }
                   htmlGenerator += "</table>";
                  

               }


I generated html TABLE in my program that assign in htmlGenerator. Now I want to Display htmlGenerator in my page.aspx. How ???
Posted
Updated 1-Feb-15 15:57pm
v3
Comments
Afzaal Ahmad Zeeshan 1-Feb-15 7:50am    
First of all, you're hiding the required information from us, in the code. Secondly you do not qoute the question well. What actually do you want?
enamul haque 1-Feb-15 21:55pm    
Sorry For That. Here My All Code...

1 solution

just put a label where you want to show the generated table. and bind your htmlGenerator to that label.
Or you can take a panel and bind that with your panel.
 
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