ShowRecordsUsingHtmlTable.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShowRecordsUsingHtmlTable.aspx.cs" Inherits="JtableExample.ShowRecordsUsingHtmlTable" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="studentTable" width="100%" align="center" cellpadding="2" cellspacing="2" border="0" bgcolor="#EAEAEA" >
<tr align="left" style="background-color:#004080;color:White;" >
<td>StudentId</td>
<td>Name </td>
<td>EmailAddress</td>
<td>Gender</td>
</tr><%=getStudentData()%>
</table>
</div>
</form>
</body>
</html>
ShowRecordsUsingHtmlTable.aspx.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace JtableExample
{
public partial class ShowRecordsUsingHtmlTable: System.Web.UI.Page {
string connectionString = ConfigurationManager.ConnectionStrings["Scon"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{ }
public string getStudentData()
{
string data = "";
using(SqlConnection conn = new SqlConnection(connectionString))
{
using(SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "UspGetStudents";
cmd.Connection.Open();
using(SqlDataReader sqlRdr = cmd.ExecuteReader())
{
// table = new DataTable();
// table.Load(reader);
if (sqlRdr.HasRows)
{
while (sqlRdr.Read())
{
int studentId = sqlRdr.GetInt32(0);
string Name = sqlRdr.GetString(1);
string EmailAddress = sqlRdr.GetString(2);
string Gender = sqlRdr.GetString(3);
data += "<tr><td>" + studentId + "</td><td>" + Name + "</td><td>" + EmailAddress + "</td><td>" + Gender + "</td></tr>";
}
}
}
}
return data;
}
}
}
}
Web.config<configuration>
<connectionStrings>
<add name="Scon" connectionString="Data Source=machineName; Initial Catalog=databaseName;Integrated Security=SSPI"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>