CREATE DYNAMIC TABLE.
Yes it easy for creating dynamic table....now what is
dynamic table?
Its just the same HTLM table or asp.net table having same structure
but getting the info from databse on demand basis(i.e DYNAMIC)....rest U ALL
KNOW.(just kidding)
So lets see how can we accomplish this:
THE DESIGN PAGE:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"
runat="server">
<title>DYNAMIC
TABLE</title>
</head>
<center><div id="divTable"
runat="server">
</div>
</center>
</body>
</html>
COME on this
much only.....yes this is the magic of ASP.NET...lets get on the code behind:
THE CODE BEHIND:
public void getdynamictable()
{
//get your data
from database or anything
String query="
select name from Test_demo where test_department=’ADMINISTRATOR’);
//HERE I am Getting all the emp name who are in admin
department.
string
tablestring = "";
//dt is datatable object which holds DB results.
tablestring += "<table
style='width:60%; border-style: solid'><tr style='Font-Bold:True; Font-Size:X-Large;
color:#000099 '><td>NAMES</td></tr>";
foreach
(DataRow dr in
dt.Rows)
{
tablestring = tablestring + "<tr style='font-family:Monotype Corsiva;
font-size: large; color: #FF3300; text-decoration:
underline'><td>" + dr[0].ToString() + "</td><td>" + "<a href='MoredetailsOn emp.aspx?name="
+ dr[0].ToString() + "'> EMP DETAILS</a>
";
}
tablestring = tablestring + "</table>";
divTable.InnerHtml = tablestring;
}
OUTPUT:
NAME | |
PIYUSH | EMP DETAILS |
TEST 1 | EMP DETAILS |
TEST 2 | EMP DETAILS |
TEST 3 | EMP DETAILS |
TEST 4 | EMP DETAILS |
TEST 5 | EMP DETAILS |
THUS ALL THE RESULT IS
FIRST STORED IN DATTABLE OBJECT.
IT ASSIGNS EACH ROW TO
TABLE ROW.In addition I have given a link to get more information on
employes(YOUR WISH) in secound column of
table.
No comments :
Post a Comment