For example it should generate 2 rows and 2columns if database contains 2 rows and 2columns of records same 3 rows and 3columns if database contains 3 rows and 3columns of records depending upon records it should display.here we should use only table with rows
for 2rows and 2columns record
it should create
Satyapriya NayakPosted Feb 24, 2012, 10:31 PM
Thanks
Suthish NairPosted Feb 19, 2012, 3:23 PM
Satyapriya NayakPosted Feb 17, 2012, 9:37 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Display_Data_Using_Table_Control._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Display_Data_Using_Table_Control
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
DataTable dt;
int i;
int j;
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
try
{
con.Open();
str = "select * from student ";
com = new SqlCommand(str, con);
ds = new DataSet();
sqlda = new SqlDataAdapter(com);
sqlda.Fill(ds, "student");
dt = ds.Tables["student"];
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
TableRow tr = new TableRow();
for (j = 0; j <= dt.Columns.Count - 1; j++)
{
TableCell tc = new TableCell();
tc.Text = dt.Rows[i].ItemArray[j].ToString();
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
}
}
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
Thanks
If this post helps you mark it as answer