Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 12th, 2006, 01:06 AM
Registered User
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default problems in creating dynamic controls

Sir,i have created two dynamic controls and bind it to the grid .but the problem is i can't add these controls to the grid and after adding how could i get these controls in the next row of the grid and also i couldn't tke values from the control. hre i s code thsat ihve written.

Dim ucxct As New ControlDyna
If Not IsPostBack Then

dtTemp = CType(Session("DYNA"), DataTable)
End If

'Put user code to initialize the page here
End Sub

Private Sub CreateTable()
If Session("DYNA") Is Nothing Then
dtTemp = New DataTable
dtTemp.Columns.Add("sct", GetType(Control))
dtTemp.Columns.Add("scr", GetType(Control))
' dtTemp.Columns.Add("abc", GetType(Control))

Session("DYNA") = dtTemp
dtTemp = CType(Session("DYNA"), DataTable)
End If

End Sub
Private Sub bindTable()
DataGrid2.DataSource = dtTemp
End Sub
Private Sub FillGrid()
Dim sql As String
Dim DT1 As New DataTable
Dim obj As New clsValidation
sql = "SELECT Firstcol,Secondcol from Dynamic where code='1' "
DT1 = obj.ReturnDataTable(sql, strconnect, erpath)
Dim i As Integer
For i = 0 To DT1.Rows.Count
If Trim(DT1.Rows(0).Item(i)) = "TextBox" Then
ElseIf Trim(DT1.Rows(0).Item(i)) = "CheckBox" Then
ElseIf Trim(DT1.Rows(0).Item(i)) = "ListBox" Then
ElseIf Trim(DT1.Rows(0).Item(i)) = "RadioButton" Then
ElseIf Trim(DT1.Rows(0).Item(i)) = "DropDown" Then
ElseIf Trim(DT1.Rows(0).Item(i)) = "LinkButton" Then
End If

End Sub
Private Sub createLinkButton()
Dim lnk As New System.Web.UI.WebControls.LinkButton
lnk.ID = "Lnkadd"
lnk.Text = "Add"
lnk.Visible = True
End Sub
Private Sub createDropDown()
Dim comp As New System.Web.UI.WebControls.DropDownList
comp.Visible = True
End Sub
Private Sub createRadBox()
Dim rb As New System.Web.UI.WebControls.RadioButton
rb.Visible = True
End Sub
Private Sub createListBox()
Dim lst As New System.Web.UI.WebControls.ListBox
lst.Visible = True
End Sub
Private Sub createchkbox()
Dim chk As New System.Web.UI.WebControls.CheckBox
chk.Visible = True
End Sub
Private Sub createTextBox()
Dim ctrl As Control
Dim phold As PlaceHolder
Dim i As Integer = 0
Dim z As Object
Dim x As New ColorConverter
Dim y As Color
z = x.ConvertFromString("#FFFFFF")
y = CType(z, Color)

Dim tb As New System.Web.UI.WebControls.TextBox
Dim TextBoxesHere As System.Web.UI.WebControls.PlaceHolder
' z = x.ConvertFromString("#dcdcdc")
'y = CType(z, Color)
tb.Visible = True
tb.BorderStyle = BorderStyle.Double
tb.BackColor = y
tb.ID = "TextBoxID" + i.ToString()
i = i + 1
' PlaceHolder1.Controls.Add(tb)
End Sub
Private Sub display(ByVal ctrl As Control)

Dim dr As DataRow
dr = dtTemp.NewRow
dr(0) = CType(ctrl, Control)
' dr(1) = CType(cTyp, String)
End Sub
Private Sub DataGrid2_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles DataGrid2.ItemCommand
If TypeOf e.CommandSource Is LinkButton Then
' bindTable()
Dim lnkTemp As New LinkButton
Dim btn As Button
Dim txtTemp As LiteralControl
Dim ctrl As Control
lnkTemp = CType(e.CommandSource, LinkButton)
Select Case Trim(lnkTemp.Text)
Case Is = "Add"
Dim drs As DataRow

drs = dtTemp.NewRow
' txtTemp = CType(e.Item.Cells(2).Controls(0), LiteralControl)
ctrl = CType(e.Item.Cells(2).Controls(0), Control)
'ctrl = DataGrid2.Controls(0).Controls(0)
' txtTemp = CType(ctrl.FindControl("TextBoxID0"), TextBox)
''drs(0) = Trim(txtTemp.Text)

'txtTemp = CType(e.Item.Cells(2).Controls(1), TextBox)
' drs(1) = Trim(txtTemp.Text)

drs(0) = ctrl
' ctrl = CType(e.Item.Cells(1).Controls(2), Control)
' drs(1) = ctrl

End Select

End If

End Sub

Private Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid2.ItemDataBound
Dim i As Integer
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.Footer Then
If dtTemp.Rows.Count > 0 Then
For i = 0 To dtTemp.Rows.Count - 1
e.Item.Cells(i).Controls.Add(CType(dtTemp.Rows(i). Item(0), Control))
End If
End If

End Sub

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic User Controls.... Jayahar ASP.NET 2.0 Professional 8 October 12th, 2007 01:27 AM
Creating Dynamic ASP.NET Server Controls Using XML kwilliams XSLT 0 October 6th, 2006 01:42 PM
Finding Dynamic controls mpdillon General .NET 0 March 30th, 2005 01:31 PM
Dynamic ActiveX Controls gabloom Excel VBA 0 September 17th, 2003 02:06 PM
Dynamic Controls tommyuk VB How-To 2 June 26th, 2003 12:54 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.