In this article we will introduce with HTMLTable control in ASP.NET using C#.
HTML Table Example Using In Asp.net
HTML Table be a Part of HTML Control using in Asp.net ToolBox. HTML table makes Row and Column and every Row and Column have multiple cells. Row makes by <tr> and every row divided into multiple cells by <td>.HTML Table makes a specific location for using other web control. Since Following Example: we maked a table using HTML Control and using C# Coding.
HTML Table.aspx(Design Page):
HTML Table.aspx(Source Code):
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Table.aspx.cs" Inherits="Table" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Table Test</title> </head> <body> <form id="Form1" runat="server"> <div> <p style="font-size: large; font-weight: bold"> HTML TABLE Using in Asp.net 4, C#</p> Rows: <asp:TextBox ID="CrRow" runat="server" Width="50px" /> <br /> Columns:<asp:TextBox ID="CrColumn" runat="server" Width="50px" /> <br /> <asp:Button ID="cmdCreate" OnClick="CreateTable_Click" runat="server" Text="Create" /> <br /> <asp:Table ID="TB" runat="server" /> </div> </form> </body> </html>
HTML Table.aspx.cs(C# Code File):
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; public partial class Table : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { } protected void CreateTable_Click(object sender, System.EventArgs e) { TB.Controls.Clear(); int Rows = Int32.Parse(CrRow.Text); int Columns = Int32.Parse(CrColumn.Text); for (int j = 0; j< Rows; j++) { TableRow Row = new TableRow(); TB.Controls.Add(Row); for (int k = 0; k < Columns; k++) { TableCell cell = new TableCell(); Label lblNew = new Label(); System.Web.UI.WebControls.TextBox txt1 = new System.Web.UI.WebControls.TextBox(); cell.Controls.Add(txt1); Row.Controls.Add(cell); } } } }
Output:
Download Source Code
[ 0 ] Comments