ASP.NET(vb.net) & Controls.Add() - Controls.Add() : Learn and example how to use Asp.net and Controls.Add()
ShotDev Focus:
- ASP.NET(vb.net) & Controls.Add()
Example
ControlAdd.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ControlAdd.aspx.vb" Inherits="ControlAdd" %> <html> <head runat="server"> <title>ShotDev.Com Tutorial</title> </head> <body> <form id="form1" runat="server"> <asp:Panel id="pnlMain1" runat="server"></asp:Panel><br /> <asp:Panel id="pnlMain2" runat="server"></asp:Panel><br /> </form> </body> </html>
ControlAdd.aspx.vb
Imports System.Data Imports System.Data.OleDb Public Class ControlAdd Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load '*** Create New Label ***' Dim lblText As New Label With lblText .Text = "My Customer" .Font.Size = "30" End With Me.pnlMain1.Controls.Add(lblText) '*** Create DataGrid ***' Dim myDataGrid As New DataGrid With myDataGrid .AutoGenerateColumns = True .DataSource = DataSource() .DataBind() End With Me.pnlMain2.Controls.Add(myDataGrid) End Sub Protected Function DataSource() Dim objConn As New System.Data.OleDb.OleDbConnection Dim dtAdapter As System.Data.OleDb.OleDbDataAdapter Dim dt As New DataTable Dim strConnString As String strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/mydatabase.mdb") & ";" objConn = New System.Data.OleDb.OleDbConnection(strConnString) objConn.Open() Dim strSQL As String strSQL = "SELECT * FROM customer" dtAdapter = New System.Data.OleDb.OleDbDataAdapter(strSQL, objConn) dtAdapter.Fill(dt) dtAdapter = Nothing objConn.Close() objConn = Nothing Return dt '*** Return DataTable ***' End Function End Class
Screenshot