DataGrid Issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Blakely

    DataGrid Issue

    (the following has also been posted to the datagrid Forum)
    In the program below, the web page has dataGrid1. the only thing that has
    been done to it at design time is to check the "Create columns automatically
    at runtime" checkbox - nothing else.

    The code below does indeed create the visual grid as expected. Furthermore
    the Cell contents and Item count all exist and contain expected values.
    However there is no columns array !! After the databind, for instance,
    DataGrid1.Colum ns(0) does not exist. There is therefore, no way to even
    reference the HeaderText (which visually shows) or any other attribute of
    the column.

    Why is this?


    Public Class WebForm1
    Inherits System.Web.UI.P age

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    If Not IsPostBack Then
    Dim SQLStr As String = "Select FirstName, LastName From
    Employees"
    Dim myConnection As New System.Data.Sql Client.SqlConne ction
    myConnection.Co nnectionString = _
    "workstatio n id=myMachine;us er id=sa;data source=myMachin e;" & _
    "persist security info=True;initi al
    catalog=NorthWi nd;password=xxx xx"
    myConnection.Op en()
    Dim cmd As New System.Data.Sql Client.SqlComma nd(SQLStr,
    myConnection)
    Dim da As New System.Data.Sql Client.SqlDataA dapter
    da.SelectComman d = cmd
    Dim dt As New DataTable
    da.Fill(dt)
    DataGrid1.DataS ource = dt
    DataGrid1.DataB ind()

    'at this point DataGrid1.Colum ns(0) does not exist
    'however...
    'DataGrid1.item s(0).cells(0).t ext = "Nancy"
    'DataGrid1.item s.Count = 9

    End If
    End Sub

    End Class

    --
    Regards,
    Gary Blakely
    Dean Blakely & Associates


    --
    Regards,
    Gary Blakely
    Dean Blakely & Associates



Working...