Create Panel in .aspx....... 23-Sep-2011
<asp:Panel ID="pnTable" runat="server">
</asp:Panel>
Code Behind File......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class DyanmicTable : System.Web.UI.Page
{
string connection = Convert.ToString(ConfigurationManager.ConnectionStrings["Test"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connection);
SqlCommand sc = new SqlCommand("Test", conn);
sc.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataAdapter sd = new SqlDataAdapter(sc);
DataSet ds = new DataSet();
sd.Fill(ds);
conn.Close();
string count = ds.Tables[0].Rows[0]["count"].ToString();
pnTable.Controls.Clear();
int tblCols = Convert.ToInt32(count);
Table tbl = new Table();
pnTable.Controls.Add(tbl);
for (int i = 0; i < tblCols; i++)
{
TableRow tr = new TableRow();
TableCell tc = new TableCell();
HyperLink hypTest = new HyperLink();
hypTest .Text = ds.Tables[1].Rows[i]["Column Name"].ToString() + "" + "Accidents";
hypTest .Font.Size = FontUnit.Small;
//hypTest .ForeColor = System.Drawing.Color.Green;
hypTest .Attributes["class"] = "test";
hypTest .NavigateUrl = "http://www.Test.com" + ds.Tables[1].Rows[0]["Column Name"].ToString();
tc.Controls.Add(hypTest );
tr.Controls.Add(tc);
tbl.Controls.Add(tr);
}
}
}
Create Procedure Test
as
begin
begin Transaction Test
select COUNT(*) as count from Table Name
select * from Table Name
order by Column Name
if(@@ERROR !=0)
Begin
rollback transaction Test
return
end
commit transaction Test
end
<asp:Panel ID="pnTable" runat="server">
</asp:Panel>
Code Behind File......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class DyanmicTable : System.Web.UI.Page
{
string connection = Convert.ToString(ConfigurationManager.ConnectionStrings["Test"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connection);
SqlCommand sc = new SqlCommand("Test", conn);
sc.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataAdapter sd = new SqlDataAdapter(sc);
DataSet ds = new DataSet();
sd.Fill(ds);
conn.Close();
string count = ds.Tables[0].Rows[0]["count"].ToString();
pnTable.Controls.Clear();
int tblCols = Convert.ToInt32(count);
Table tbl = new Table();
pnTable.Controls.Add(tbl);
for (int i = 0; i < tblCols; i++)
{
TableRow tr = new TableRow();
TableCell tc = new TableCell();
HyperLink hypTest = new HyperLink();
hypTest .Text = ds.Tables[1].Rows[i]["Column Name"].ToString() + "" + "Accidents";
hypTest .Font.Size = FontUnit.Small;
//hypTest .ForeColor = System.Drawing.Color.Green;
hypTest .Attributes["class"] = "test";
hypTest .NavigateUrl = "http://www.Test.com" + ds.Tables[1].Rows[0]["Column Name"].ToString();
tc.Controls.Add(hypTest );
tr.Controls.Add(tc);
tbl.Controls.Add(tr);
}
}
}
Store Procedure...
Create Procedure Test
as
begin
begin Transaction Test
select COUNT(*) as count from Table Name
select * from Table Name
order by Column Name
if(@@ERROR !=0)
Begin
rollback transaction Test
return
end
commit transaction Test
end
Comments
Post a Comment