Datagrid Not Displaying

Discussion in 'ASP .Net Datagrid Control' started by Roy, Jan 24, 2005.

  1. Roy

    Roy Guest

    Datagrid below. It will not display. The page shows nothing but the
    html header. I have tested the query in query analyzer. Records exist
    and should be displayed. I've stripped out all extraneous code to try
    to narrow down where the syntactic flaw is but am still coming up
    short. What am I missing here? I bet it's obvious... :-/



    Option Strict On
    imports Microsoft.VisualBasic
    imports System
    imports System.Data
    imports System.Data.SqlClient
    imports System.Web
    imports System.Web.UI
    imports System.Web.UI.WebControls
    imports System.Web.UI.HtmlControls

    Public Class Tier2Grid : Inherits System.Web.UI.Page

    Protected DataGrid As System.Web.UI.WebControls.DataGrid
    Dim MyConnection As SqlConnection
    Dim gPoe As String
    Dim gVoydoc As String

    Public Sub Page_Load ( sender As Object, e As EventArgs )

    IF (ISPOSTBACK = FALSE) THEN
    BindData()
    End If
    End Sub

    Public Sub BindData()

    Dim DS As DataSet
    Dim MyCommand As SqlDataAdapter

    gPoe = Request.QueryString("poe")
    gVoydoc = Request.QueryString("voydoc")
    Dim SelectCmd As String = "SELECT TOP 500 IsNull(ocean_carrier_cd, '')
    as 'Carrier'," _
    & " IsNull(carrier_booking_nr, '') as 'Booking Num', IsNull(equipment,
    '') as 'Equipment'," _
    & " IsNull(Van_Owner, '') as 'Van Owner', IsNull(Tcon_Container_Num,'')
    'Container Num', IsNull(Event_Code,'') as 'Event Code'," _
    & " IsNull(Minof315_event_date,'') as 'Sail Date', IsNull(TCN,'') as
    'TCN',IsNull(POD,'') as PoD," _
    & " IsNull(Ship_Name,'') as 'Ship Name',IsNull(Pcfn,'') as
    'PCFN',IsNull(LastEvent,'') as 'Last Event',IsNull(lasteventloc,'') as
    'LE Location'," _
    & " IsNull(LastEventdt,'') as 'LE Date',IsNull(Lastevent_shipname,'')
    as 'LE Ship Name',IsNull(lastevent_scac,'') as 'LE SCAC'," _
    & " IsNull(consigneecity,'') as 'Consignee City'" _
    & " FROM firstvd WHERE voydoc = '"& gVoydoc & "' AND poe = '"& gPoe
    &"'"

    MyConnection = New
    SqlConnection("server=localhost;uid=itv;pwd=itv_$ql!;database=maersk_test")
    MyCommand = New SqlDataAdapter(SelectCmd, MyConnection)

    DS = new DataSet()

    MyCommand.Fill(DS)
    DataGrid.DataSource = DS
    DataGrid.DataBind()
    Response.Write(SelectCmd)

    End Sub

    Sub DataGrid_EditCommand(Sender As Object, E As
    DataGridCommandEventArgs)
    DataGrid.EditItemIndex = CInt(E.Item.ItemIndex)
    BindData()
    End Sub

    Sub DataGrid_CancelCommand(Sender As Object, E As
    DataGridCommandEventArgs)
    DataGrid.EditItemIndex = -1
    BindData()
    End Sub

    Sub DataGrid_UpdateCommand(Sender As Object, E As
    DataGridCommandEventArgs)

    End Sub

    End Class
    Roy, Jan 24, 2005
    #1
    1. Advertising

  2. Roy

    Roy Guest

    Never mind. After 2 days of blank stares I naturally figure it out 5
    minutes after posting it here. gah!
    My .aspx page looked like the below example... my columns were outside
    my grid. *rolling eyes at myself*
    <asp:datagrid>
    ....
    </asp:datagrid>
    <columns>
    ....
    </columns>
    Roy, Jan 24, 2005
    #2
    1. Advertising

  3. Roy

    Roy Guest

    Hrmm....

    Actually, refresh this question. Heh.
    Now the page displays, but when I click edit, the datagrid vanishes.
    IOW, the page refreshes, but the datagrid is not displayed. *sigh*
    Roy, Jan 24, 2005
    #3
  4. Roy

    Roy Guest

    And scratch this one too. For those future .net newcomers who google
    this in the future... try setting the enableviewstate property in your
    datagrid to "true."

    ;)
    Roy, Jan 24, 2005
    #4
  5. Roy

    Mike Ryan Guest

    > For those future .net newcomers who google
    > this in the future... try setting the enableviewstate property in your
    > datagrid to "true."


    Or the alternative with disabled viewstate: bind on every page load (not
    just when PostBack is false). :)
    Mike Ryan, Jan 24, 2005
    #5
    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. Mervin Williams

    DataGrid not displaying in new mode

    Mervin Williams, May 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    850
    Mervin Williams
    May 6, 2004
  2. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    Datagrid problem not displaying anything on the screen!!

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Sep 30, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    456
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Sep 30, 2004
  3. .Net Sports

    datagrid not displaying data table data

    .Net Sports, Aug 30, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,763
    .Net Sports
    Aug 31, 2005
  4. .Net Sports

    Datagrid footer not displaying data

    .Net Sports, Mar 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,282
    Ignacio Machin \( .NET/ C# MVP \)
    Mar 13, 2006
  5. Replies:
    3
    Views:
    295
    Mark Rae
    Jun 29, 2007
Loading...

Share This Page