Hi Richard,
If I didn't misunderstand you, you want to populate a datatable from the
datasource bound to a datagrid. If it is the case, you can get the binding
datatable through the DataSource property of a datagrid. Suppose that a
datagrid was bound to a dataview. For example,
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
' Load this data only once.
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub
Function CreateDataSourc e() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn("Int egerValue", GetType(Int32)) )
dt.Columns.Add( New DataColumn("Str ingValue", GetType(String) ))
dt.Columns.Add( New DataColumn("Cur rencyValue", GetType(Double) ))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSour ce
If you want to get the datatable bound to the datagrid, you can do as
follows:
Dim dt As DataTable
Dim dv As DataView
dv = DataGrid1.DataS ource
dt = dv.Table
Response.Write( dt.Columns.Coun t)
If I have misunderstood your concern, please feel free to let me know.
Best regards,
Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.