3 Replies - 7833 Views - Last Post: 20 July 2012 - 06:28 PM

#1 silentcore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-May 09

Problem: Dynamic HTML Table

Posted 20 July 2012 - 01:20 AM

Hi There.
I am having a problem in populating html table from database dynamically. What i mean is that i have a table in database that have let say 10 enteries, I want to display those 10 entries in a html table using loop. I am new to ASP.NET, I've previously woked in php. I can present the scenario in php and please help me do the same thing in ASP.NET. In php what i normally do is search the database, grab the table in fetch array and in html table i create one row and use while loop so that all of the 10 entries are populated at runtime. Here is a demonstration

code in head:


 <?php
        $query = mysql_query("select * from table");
        ?>


in body code:

<table>
        <tr>
        <td>Username</td>
        <td>Email</td>
        <td>Position</td>
        <td>Status</td>
        </td>
        //start of the loop
        <?php while($fetch = mysql_fetch_array($query) { ?>
        <tr>
        <td><?php echo $fetch["username"]; ?> </td>
        <td><?php echo $fetch["email"]; ?> </td>
        <td><?php echo $fetch["position"]; ?> </td>
        <td><?php echo $fetch["status"]; ?> </td>
        </tr><?php } ?>//End of loop
        </table>





When i use foreach loop in asp.net to do the same thing the it displays only the last row in the database table...I am using three tier architecture...



 projectsLoad_BLL bo = new projectsLoad_BLL();
        
                    DataSet ds = new DataSet();
                    DataTable dt = ds.Tables[0];
                    int num = 1;
                    foreach (DataRow dr in dt.Rows)
                    {
                        lblno.Text = num.ToString();
                        lblusername.Text = dr["username"].ToString();
                        lblemail.Text = dr["email"].ToString();
                        lblposition.Text = dr["position"].ToString();
                        lblstatus.Text = dr["status"].ToString();
                        dt.NewRow();
                        num++;
                    }




In HTML Table:


 <table>
            <thead>
                 <tr>
                 <th>No.</th>
                 <th>Username</th>
                 <th>Email</th>
                 <th>Position</th>
                  <th>Status</th>
                   </tr>
                     </thead>
                          <tbody>
                             <tr>
                                <td><asp:Label ID="lblno" runat="server" Text="Label"></asp:Label> </td>
                                <td><asp:Label ID="lblusername" runat="server" Text="Label"></asp:Label></td>
                                <td><asp:Label ID="lblemail" runat="server" Text="Label"></asp:Label></td>
                                <td><asp:Label ID="lblposition" runat="server" Text="Label"></asp:Label></td>
                                <td><asp:Label ID="lblstatus" runat="server" Text="Label"></asp:Label></td>
                                            </tr>
                                        </tbody>
                                    </table>



I know that this method is wrong...if anyone can point to the right direction...thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Problem: Dynamic HTML Table

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: Problem: Dynamic HTML Table

Posted 20 July 2012 - 03:12 AM

lookup how to use the GridView control instead of trying to create your own table.
Was This Post Helpful? 0
  • +
  • -

#3 silentcore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-May 09

Re: Problem: Dynamic HTML Table

Posted 20 July 2012 - 06:01 AM

View PostNakor, on 20 July 2012 - 03:12 AM, said:

lookup how to use the GridView control instead of trying to create your own table.


I don't want to use gridview...I am having trouble managing it...What i want to do is add an edit button for every row. And when I click on edit button a pop window should show with the detailed information of that user that can be get by his id in that row to update his record...
Was This Post Helpful? 0
  • +
  • -

#4 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: Problem: Dynamic HTML Table

Posted 20 July 2012 - 06:28 PM

You asked for someone to point you in the right direction. That's what I did. What you are wanting to do is really a very simple task using a GridView or ListView control and is the diretion you should be taking this. I recommended the GridView because it has an easier learning curve than the ListView, although the ListView gives you a lot more control of the generated html. Learning any new technology can be a challenge, but just because it's a challenge does not mean it should be avoided. Spend a little more time learning the tools now and you will save yourself a lot of time and effort in the future. If you have specific problems with using the GridView please post the questions you have on it and I'll do my best to answer them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1