ASP.NET中的HTML表 [英] Html Table in ASP.NET

查看:62
本文介绍了ASP.NET中的HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ASP.NET中动态获取HTML表中的数据?

How to fetch data in Html Table dynamically in ASP.NET?

推荐答案

请参阅
CP答案


如果要获取html表中的数据或值,您必须阅读以下内容:
表必须具有runat ="server"属性和特定ID.
例如,表ID可能是tbl:

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 :

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; 
  }
 }
 }
}



但是,如果您想用任何数据源填充html表,则必须使用数据绑定.
在这种情况下,html表无法通过该模型运行.您应该使用Data Grid控件,并且此控件将自身呈现到html表中!
是正确的??!!!我不知道!!!



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!!!


您可以使用Gridview

像这样

you can use Gridview

like this

<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


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();
   }


这篇关于ASP.NET中的HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆