Lab Report - Dynamic Table

This lab demonstrates the creation of a dynamic table in ASP.NET Web Forms using VB.NET. The table is generated based on user input for the number of rows and columns, and it includes interactive controls like DropDownLists and RadioButtonLists.

File 1: DynamicTable.aspx

This file defines the front-end structure of the web page. It includes two DropDownLists for selecting the number of rows and columns, a button to generate the table, and a placeholder to display the dynamically generated table.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DynamicTable.aspx.vb" Inherits="DynamicTable" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Dynamic Table</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="RowsDropDown" runat="server">
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
                <asp:ListItem>4</asp:ListItem>
                <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="ColumnsDropDown" runat="server">
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
                <asp:ListItem>4</asp:ListItem>
                <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList>
            <asp:Button ID="GenerateButton" runat="server" Text="Generate Table" OnClick="GenerateButton_Click" />
            <br /><br />
            <asp:PlaceHolder ID="TablePlaceHolder" runat="server"></asp:PlaceHolder>
        </div>
    </form>
</body>
</html>
    

File 2: DynamicTable.aspx.vb

This file contains the back-end logic for generating the dynamic table. It handles the button click event, reads the selected number of rows and columns, and dynamically creates a table with DropDownLists in the first column and RadioButtonLists in the last row.

Partial Class DynamicTable
    Inherits System.Web.UI.Page

    Protected Sub GenerateButton_Click(sender As Object, e As EventArgs)
        Dim rows As Integer = Integer.Parse(RowsDropDown.SelectedValue)
        Dim columns As Integer = Integer.Parse(ColumnsDropDown.SelectedValue)

        Dim table As New Table()
        table.BorderWidth = 1
        table.BorderColor = System.Drawing.Color.Red

        For i As Integer = 1 To rows
            Dim row As New TableRow()

            For j As Integer = 1 To columns
                Dim cell As New TableCell()

                If j = 1 Then
                    ' First cell of each row: DropDownList
                    Dim ddl As New DropDownList()
                    ddl.Items.Add("Urdu")
                    ddl.Items.Add("English")
                    ddl.Items.Add("Arabic")
                    ddl.Items.Add("Chinese")
                    cell.Controls.Add(ddl)
                Else
                    ' Other cells: Display {row, column}
                    cell.Text = String.Format("{{{0},{1}}}", i, j)
                End If

                ' Last row: Add RadioButtonList
                If i = rows Then
                    Dim rbl As New RadioButtonList()
                    rbl.Items.Add("1")
                    rbl.Items.Add("2")
                    rbl.Items.Add("3")
                    rbl.Items.Add("4")
                    cell.Controls.Add(rbl)
                    cell.BackColor = System.Drawing.Color.Gray
                End If

                row.Cells.Add(cell)
            Next

            table.Rows.Add(row)
        Next

        TablePlaceHolder.Controls.Clear()
        TablePlaceHolder.Controls.Add(table)
    End Sub
End Class
    
Web hosting by Somee.com