You can create the Dynamic controls through SQL Server using VB.Net. For Example First you create the table createtextbox its have two field name label(nchar(10)),textbox(numeric(18, 0)). You just drag and drop the Panel control from toolbox and place it on form. Then you put the below code and excute it.
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Text Imports System.Windows.Forms Imports System.Data.SqlClient Public Class Form1 Dim con As SqlClient.SqlConnection Dim cmd As SqlClient.SqlCommand Dim rd As SqlClient.SqlDataReader Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con = New SqlClient.SqlConnection("Data Source=xxxxx;Initial Catalog=Emp;Integrated Security=True") con.Open() cmd = New SqlCommand("select label,textbox from createtextbox", con) rd = cmd.ExecuteReader()
While (rd.Read()) Dim b As String b = rd.Item("textbox").ToString Dim y As Integer y = Convert.ToInt32(b) Dim i As Integer For i = 1 To y Dim l As New Label l.Location = New Point(50, y) y = y + 32 Panel1.Controls.Add(l) 'me.Controls.Add(l)
l.Text = rd.Item("label").ToString() Dim x As Integer Dim t As New TextBox Dim j As Integer x = Convert.ToInt32(b) For j = 1 To x t.Location = New Point(150, x) x = x + 31 Panel1.Controls.Add(t) 'me.Controls.Add(t) Next Next ' rd.Close() 'con.Close() End While
End Sub End Class
|
No feedbacks found. Be the first to respond and make money from revenue sharing program.
|