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];
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 ???