programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Friday, February 20, 2015

Display Data in HTML Table from Database using

Display Data in HTML Table from Database using

HTML Table from Database using

In this post we describe how to print data from data base in to html page by C# code.

Code in html page for display data:

<html xmlns="">
<head runat="server">
<title>Display Data from Database in HTML Table in</title>
<form id="form1" runat="server">
<asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>

Now open code behind file C# code:

SqlConnection scon = new SqlConnection("<connection string>");
StringBuilder htmlTable = new StringBuilder();
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
using (SqlCommand scmd = new SqlCommand())
scmd.Connection = scon;
scmd.CommandType = CommandType.Text;
scmd.CommandText = "SELECT * FROM Emp";
SqlDataReader articleReader = scmd.ExecuteReader();

htmlTable.Append("<table border='1'>");
htmlTable.Append("<tr><th>SlNo.</th><th>Name</th><th>Mobile Number</th><th>EmailId</th></tr>");

if (articleReader.HasRows)
while (articleReader.Read())
htmlTable.Append("<td>" + articleReader["EMPID"]+ "</td>");
htmlTable.Append("<td>" + articleReader["EMPName"] + "</td>");
htmlTable.Append("<td>" + articleReader["EMPMobno"] + "</td>");
htmlTable.Append("<td>" + articleReader["EMPEmailId"] + "</td>");

PlaceHolder1.Controls.Add(new Literal { Text = htmlTable.ToString() });


No comments:

Post a Comment