DataGrid Issue

Discussion in 'ASP .Net' started by Gary Blakely, Oct 6, 2005.

  1. Gary Blakely

    Gary Blakely Guest

    (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.Columns(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.Page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    Dim SQLStr As String = "Select FirstName, LastName From
    Employees"
    Dim myConnection As New System.Data.SqlClient.SqlConnection
    myConnection.ConnectionString = _
    "workstation id=myMachine;user id=sa;data source=myMachine;" & _
    "persist security info=True;initial
    catalog=NorthWind;password=xxxxx"
    myConnection.Open()
    Dim cmd As New System.Data.SqlClient.SqlCommand(SQLStr,
    myConnection)
    Dim da As New System.Data.SqlClient.SqlDataAdapter
    da.SelectCommand = cmd
    Dim dt As New DataTable
    da.Fill(dt)
    DataGrid1.DataSource = dt
    DataGrid1.DataBind()

    'at this point DataGrid1.Columns(0) does not exist
    'however...
    'DataGrid1.items(0).cells(0).text = "Nancy"
    'DataGrid1.items.Count = 9

    End If
    End Sub

    End Class

    --
    Regards,
    Gary Blakely
    Dean Blakely & Associates
    www.deanblakely.com
     
    Gary Blakely, Oct 6, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordo
    Replies:
    0
    Views:
    470
    Jordo
    Oct 31, 2003
  2. =?Utf-8?B?UHVtcw==?=

    Datagrid Paging Issue

    =?Utf-8?B?UHVtcw==?=, Feb 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    631
    Paul M
    Feb 5, 2004
  3. Arvind P Rangan

    Same DataGrid Issue

    Arvind P Rangan, Mar 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    655
    Arvind P Rangan
    Mar 1, 2004
  4. Srini
    Replies:
    11
    Views:
    994
    Arne Vajhøj
    Jun 1, 2008
  5. Andreas Klemt
    Replies:
    0
    Views:
    338
    Andreas Klemt
    Oct 8, 2003
Loading...

Share This Page