Micharel
Thanks for your suggestion. I'm a little confused by your reponse though.
I've copied my code below. Can you help?
regards,
Bruce
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents dgTest As System.Web.UI.WebControls.DataGrid
Protected WithEvents ddlTest As System.Web.UI.WebControls.DropDownList
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim RowView As DataView
Private Function getRows() As ArrayList
Dim arrReturn As New ArrayList
Dim objRow1 As New clsRow
Dim objRow2 As New clsRow
objRow1.RowId = 1
objRow1.DropDownId = 2
objRow1.Name = "One"
arrReturn.Add(objRow1)
objRow2.RowId = 3
objRow2.DropDownId = 4
objRow2.Name = "Two"
arrReturn.Add(objRow2)
Return arrReturn
End Function
ReadOnly Property InvoiceRows() As DataTable
Get
Dim tmpDataTable As New DataTable
Dim dr As DataRow
Dim arrRows As ArrayList
Dim objRow As New clsRow
tmpDataTable.Columns.Add(New DataColumn("RowID", GetType(Integer)))
tmpDataTable.Columns.Add(New DataColumn("DropDown", GetType(DropDownList)))
arrRows = getRows()
For Each objRow In arrRows
Dim ddlTest As New DropDownList
dr = tmpDataTable.NewRow
dr(0) = objRow.RowId
ddlTest.DataSource = CreateDDL(arrRows)
ddlTest.DataValueField = "ValueField"
ddlTest.DataTextField = "TextField"
ddlTest.DataBind()
dr(1) = ddlTest
tmpDataTable.Rows.Add(dr)
Next
Return tmpDataTable
End Get
End Property
Private Function populateDataGrid()
dgTest.DataSource = InvoiceRows
dgTest.DataBind()
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim arrRows As ArrayList
If Not Page.IsPostBack Then
populateDataGrid()
End If
End Sub
Private Function CreateRow(ByVal Value As String, ByVal Text As String,
ByVal dt As DataTable) As DataRow
Dim dr As DataRow = dt.NewRow()
dr(0) = Value
dr(1) = Text
Return dr
End Function
Private Function CreateDDL(ByVal arrList As ArrayList) As ICollection
Dim dt As DataTable = New DataTable
Dim objRow As clsRow
dt.Columns.Add(New DataColumn("ValueField", GetType(String)))
dt.Columns.Add(New DataColumn("TextField", GetType(String)))
For Each objRow In arrList
dt.Rows.Add(CreateRow(objRow.DropDownId, objRow.Name, dt))
Next
Dim dv As DataView = New DataView(dt)
Return dv
End Function
End Class