Popular Posts

Thursday, 22 August 2013

CREATE DYNAMIC TABLE

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
PIYUSHEMP DETAILS
TEST 1EMP DETAILS
TEST  2EMP DETAILS
TEST  3EMP DETAILS
TEST  4EMP DETAILS
TEST  5EMP 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.



So IT DONE EASY AND PERFECT..HENCE YOUR PROBLEM SOVED ..............................So JUST COPY AND (!!!!UNDERSTAND.......) AND GET AMAZED ON YOUR INTELLIGENCEIF ANY ERROR OR SUGGESTION IS ,ALWAYS WELCOME....................................................................THANKS FOR BEARING.............................................................................................................................. 

No comments :

Post a Comment