Creating a Table Control Using ASP.Net and Visual Basic.Net
Author: Faraz
In the article I will show you the technique of a creating table control in code. I will also discuss some of the formatting tips.
You may find that you need to write out to visitors’ browsers a basic HTML table. But that table cannot be predefined. It may depend on some visitors input or it may depend on the values in a database table. This technique shows you how to create a Table control in code and display that control on the rendered page.
The web form defined for this technique creates a Table control when the page is first loaded. The table displays the coordinates of each cell through the rendered HTML table. For this you only have to define a Place Holder control on the web form.
Now add the following code in the code behind:
First, you defined a Table control:
Then you select the format in which you want the table to be displayed:
Define variables that will be used in loop to determine the number of rows and columns:
Now using the loops add the Rows and Columns on the Form:
Here the outer loop is used for Rows and inner loop is used for columns. Finally the table is added to the page using Place Holder control:
Summary:
- Create a web form add the place holder control set its id property.
- Add the above mention code in the code behind.
- Run the application and use it in your future applications.