• home
  • Email: trainings@synapseindia.careers



Working with ASP.NET Table Control Part- II

Mar 14, 2016

One of the standard control in ASP.NET is Table Control which allows you to get control over displaying records in tabular format . In short, programmer has whole command in his hand to write code for same. Some of the rich data controls like GridView also work on the same concept of rendering table to client after fetching records from server. In this article we will cover the working of Table, for which we are taking the number of rows and columns from user and then creating a table accordingly. We have used some standard controls like TextBoxes for accepting number of rows and columns along with Button for submitting the data to server. See the code for .cs page below :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)
Table tb = new Table(); // Instance of Table is creatd
tb.BorderWidth = Unit.Pixel(2); // Fixing Table Border Width
tb.BorderStyle = BorderStyle.Inset; // Fixing Table BorderStyle
tb.GridLines = GridLines.Both; // Fixing Table GridLines
tb.Caption = TextBox1.Text.ToUpper() ; // Fixing Table's Caption.

int rows = int.Parse(TextBox2.Text); // Accepting number of rows after converting into Int.
int colm = int.Parse(TextBox3.Text); // Accepting number of columns after converting into Int.
// Iterating for creating rows and columns

for (int r = 0; r < rows; r++)
TableRow tr = new TableRow(); // Creating TableRow

for (int c = 0; c < colm; c++)
TableCell cell = new TableCell(); // Creating TableCell
cell.Text = "{" + r + "," + c + "}"; // Filling Text in TableCell
tr.Controls.Add(cell); // Adding Table Cell in TableRow

tb.Controls.Add(tr); //Adding TableRow created into Table
this.Controls.Add(tb); //Adding Table into Current Page
The above code very easily creates a table of your provided dimensions (E.G. numbers of columns and rows). Similarly we can create table for displaying many records available in either File or Relational database. SynapseIndia Training offers such learnings to all freshers who want to make their career in .NET. We are providing standard modules of ASP.NET to our trainees to allow implementation of every concepts clearly and effectively. SynapseIndia Training has chosen some of the standard technologies from mostly used SynapseIndia Technologies like ASP.NET , jQuery , ADO.NET , EF , AJAX and LINq in the project development as an part of training.  

SynapseIndia (CEO: Shamit Khemka)

Leave a Reply

Your email address will not be published.