Skip to main content

How to use Table in asp.net


Table Web Server Control



ASP.NET Table web server control displays a table on a web page. It is a .NET web server control so we can program it in server code such as add, and remove table rows, and cells programmatically. TableRow and TableCell web server controls allow us to display content for the Table.




Table server control displays tabular data and we can format Table server control using its built-in methods and properties. The big difference between HTML table and asp.net Table server control is that we can manipulate Table server control using an object model. Generally, we should use Table server control when we intend to add or remove rows and cells (columns) programmatically at run time.




Table server control acts as a parent (container) for TableRows controls. Table control's Rows property is a collection of TableRow objects. Each TableRow control has a collection named Cells. Cells collection contains TableCell objects.




Actually, table server control displays the TableCell controls the content. TableCell control's Text property value stores any HTML text. you also can add and display controls inside the Table cell.




The Table class has many properties to control its appearance such as BackColor, ForeColor, BorderColor, BorderWidth, BorderStyle, Height, BackImageUrl, Caption, CellPadding, CellSpacing, CssClass, GridLines, Font, HorizontalAlign, Style, SkinID, etc. TableRow and TableCell control support many of these properties as well. Even we can change any individual cell's or row's appearance and look.




Table server control can display data from a database. But table control does not provide any property that we can use to directly display database data. The following C# example code describes more about ASP.NET Table web server control.





TableExample.aspx



<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to use Table in asp.net</title>
</head>
<body style="padding:25px">
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
How to use Table in asp.net
</h2>
<hr width="450" align="left" color="Gainsboro" />
<asp:Table ID="Table1"
runat="server"
Font-Size="X-Large"
Width="550"
Font-Names="Palatino"
BackColor="Orange"
BorderColor="DarkRed"
BorderWidth="2"
ForeColor="Snow"
CellPadding="5"
CellSpacing="5"
>
<asp:TableHeaderRow
runat="server"
ForeColor="Snow"
BackColor="OliveDrab"
Font-Bold="true"
>
<asp:TableHeaderCell>Serial</asp:TableHeaderCell>
<asp:TableHeaderCell>Name</asp:TableHeaderCell>
<asp:TableHeaderCell>Value</asp:TableHeaderCell>
</asp:TableHeaderRow>
<asp:TableRow
ID="TableRow1"
runat="server"
BackColor="OrangeRed"
>
<asp:TableCell>1</asp:TableCell>
<asp:TableCell>Azure</asp:TableCell>
<asp:TableCell>#F0FFFF</asp:TableCell>
</asp:TableRow>
<asp:TableRow
ID="TableRow2"
runat="server"
BackColor="DarkOrange"
>
<asp:TableCell>2</asp:TableCell>
<asp:TableCell>Beige</asp:TableCell>
<asp:TableCell>#F5F5DC</asp:TableCell>
</asp:TableRow>
<asp:TableRow
ID="TableRow3"
runat="server"
BackColor="OrangeRed"
>
<asp:TableCell>3</asp:TableCell>
<asp:TableCell>Bisque</asp:TableCell>
<asp:TableCell>#FFE4C4</asp:TableCell>
</asp:TableRow>
<asp:TableRow
ID="TableRow4"
runat="server"
BackColor="DarkOrange"
>
<asp:TableCell>4</asp:TableCell>
<asp:TableCell>Crimson</asp:TableCell>
<asp:TableCell>#DC143C</asp:TableCell>
</asp:TableRow>
<asp:TableRow
ID="TableRow5"
runat="server"
BackColor="OrangeRed"
>
<asp:TableCell>5</asp:TableCell>
<asp:TableCell>Cyan</asp:TableCell>
<asp:TableCell>#00FFFF</asp:TableCell>
</asp:TableRow>
<asp:TableFooterRow
runat="server"
BackColor="DarkOrange"
>
<asp:TableCell
ColumnSpan="3"
HorizontalAlign="Right"
Font-Italic="true"
>
Number of colors 5
</asp:TableCell>
</asp:TableFooterRow>
</asp:Table>
</div>
</form>
</body>
</html>




Popular posts from this blog

Restricting Jetpack Compose TextField to Numeric Input Only

Jetpack Compose has revolutionized Android development with its declarative approach, enabling developers to build modern, responsive UIs more efficiently. Among the many components provided by Compose, TextField is a critical building block for user input. However, ensuring that a TextField accepts only numeric input can pose challenges, especially when considering edge cases like empty fields, invalid characters, or localization nuances. In this blog post, we'll explore how to restrict a Jetpack Compose TextField to numeric input only, discussing both basic and advanced implementations. Why Restricting Input Matters Restricting user input to numeric values is a common requirement in apps dealing with forms, payment entries, age verifications, or any data where only numbers are valid. Properly validating input at the UI level enhances user experience, reduces backend validation overhead, and minimizes errors during data processing. Compose provides the flexibility to implement ...

jetpack compose - TextField remove underline

Compose TextField Remove Underline The TextField is the text input widget of android jetpack compose library. TextField is an equivalent widget of the android view system’s EditText widget. TextField is used to enter and modify text. The following jetpack compose tutorial will demonstrate to us how we can remove (actually hide) the underline from a TextField widget in an android application. We have to apply a simple trick to remove (hide) the underline from the TextField. The TextField constructor’s ‘colors’ argument allows us to set or change colors for TextField’s various components such as text color, cursor color, label color, error color, background color, focused and unfocused indicator color, etc. Jetpack developers can pass a TextFieldDefaults.textFieldColors() function with arguments value for the TextField ‘colors’ argument. There are many arguments for this ‘TextFieldDefaults.textFieldColors()’function such as textColor, disabledTextColor, backgroundColor, cursorC...

jetpack compose - Image clickable

Compose Image Clickable The Image widget allows android developers to display an image object to the app user interface using the jetpack compose library. Android app developers can show image objects to the Image widget from various sources such as painter resources, vector resources, bitmap, etc. Image is a very essential component of the jetpack compose library. Android app developers can change many properties of an Image widget by its modifiers such as size, shape, etc. We also can specify the Image object scaling algorithm, content description, etc. But how can we set a click event to an Image widget in a jetpack compose application? There is no built-in property/parameter/argument to set up an onClick event directly to the Image widget. This android application development tutorial will demonstrate to us how we can add a click event to the Image widget and make it clickable. Click event of a widget allow app users to execute a task such as showing a toast message by cli...