Click here to Skip to main content
14,974,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to fetch data in Html Table dynamically in ASP.NET?
Posted
Comments
Syed Salman Raza Zaidi 7-Feb-12 2:16am
   
table should generate dynamically or it is already generated?

   
if you want to fetch data or value from html table you must read following :
Table must has runat="server" attrib and specific id.
for example may table id is tbl :

C#
string myVar=string.Empty;
foreach(HtmlTableRow row in tbl.Rows)
{
 foreach(HtmlTableCell cell in row.Cells)
 {
  // TODO
  // example if cells has controls 
 foreach(Control ctrl in cell.Controls)
 {
  if(ctrl is Lable)
  {
   myVar=(ctrl as Lable).Text; 
  }
 }
 }
}


but if you want to fill html table by any data source you must be use data binding .
in this case html table can not work by this model . you should use Data Grid control and this control render self to html table !!
is correct??!!! i dont know!!!
   
v2
you can use Gridview

like this

HTML
<asp:GridView ID="grdviewEmployeeMemberList" runat="server"
                        AutoGenerateColumns="False"
                        GridLines="None"
                        AllowPaging="true"
                        CssClass="mGrid"
                        PageSize="20"
                        PagerStyle-CssClass="pgr"
                        AlternatingRowStyle-CssClass="alt"
                        OnPageIndexChanging="grdviewEmployeeMemberList_PageIndexChanging">
                        <Columns>
                            <asp:BoundField DataField="EmployeeId" HeaderText="Employee Id" />
                            <asp:BoundField DataField="CardNO" HeaderText="Card Number" />
                            <asp:BoundField DataField="PlanCode" HeaderText="Plan Code" />
                            <asp:BoundField DataField="FirstName" HeaderText="First Name" />
                            <asp:BoundField DataField="LastName" HeaderText="Last Name" />
                            <asp:BoundField DataField="MiddleName" HeaderText="Middle Name" />
                            <asp:BoundField DataField="FamilyID" HeaderText="FamilyID" />
                            <asp:BoundField DataField="MemberType" HeaderText="MemberType" />
                            <asp:BoundField DataField="Active" HeaderText="Active" />
                        </Columns>
                        <PagerSettings Position="Bottom"  PageButtonCount="5" />
                        <PagerStyle HorizontalAlign="Right" CssClass="pgr" />
                    </asp:GridView>


on Code Behind


HTML
protected void Page_Load(object sender, EventArgs e){
       if (this.Page.IsPostBack)
       {
           gviewBindEmpMemList();
       }
     }

   public void gviewBindEmpMemList(){
         empList = emp.GetAllEmployeesByWorksiteCode
         this.grdviewEmployeeMemberList.DataSource = empList;
         this.grdviewEmployeeMemberList.DataBind();
   }
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900