Help me understand what is wrong (Data not showing)

Discussion in 'ASP .Net Datagrid Control' started by Lorenzo, Dec 28, 2005.

  1. Lorenzo

    Lorenzo Guest

    Hello there I have somenthing pretty strange to me that I am trying to
    understand but I seem to fail.

    I have the following simple code that works fine in one scenario and give me
    an hard time in another one. I have understood where the problem is but
    there is a main concept that I am not getting and I need to understand.
    What I am doing is programmatically create a table and filling it with 2
    records and then bind it to a GridView control. It works fine if a place
    the code in one single page, it does not if I place the code in the code
    behind...

    Code that works within the tag <SCRIPT> is here:
    <%@ Import Namespace = "System.Data" %>

    <script language="VB" runat="server">

    Sub Page_Load(sender as Object, e as EventArgs)

    If Not Page.IsPostBack then

    'Create the DataTable

    Dim dt as New DataTable()


    'Create the columns

    Dim dcName as New DataColumn("Name", GetType(String))

    Dim dcAge as New DataColumn("Age", GetType(Integer))


    'Add the columns to the DataTable's Columns collection

    dt.Columns.Add(dcName)

    dt.Columns.Add(dcAge)


    'Add some rows

    Dim dr as DataRow

    dr = dt.NewRow()

    dr("Name") = "Scott"

    dr("Age") = 25

    dt.Rows.Add(dr)


    dr = dt.NewRow()

    dr("Name") = "Jisun"

    dr("Age") = 24

    dt.Rows.Add(dr)


    dr = dt.NewRow()

    dr("Name") = "Sam"

    dr("Age") = 5

    dt.Rows.Add(dr)



    'Bind the DataTable to the DataGrid

    dgPeople.DataSource = dt

    dgPeople.DataBind()

    End If

    End Sub

    </script>

    The same code place in a code behind page differs only in the Page_Load
    event that has the following code:

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

    If Not Page.IsPostBack Then

    'Create the DataTable

    Dim dt As New DataTable()

    ....the rest of the code is exactly the same

    Here I don't get an error but my GridView doesn' show any data, why is that
    ? Could someone refer me to to what the ByVal does? My little knowledges
    tell me that is a difference that is so that variables are referred by their
    address position in memory instead of a copy of the actual value. This is
    as far as I go, but you can tell I have no very much clear what all that
    means. I really thank someone who can give me a hint to make my code above
    work (that should be simple) and refer me to a resource where I can learn
    more about byRef and ByVal.

    I hope I was clear.
    Lore
    Lorenzo, Dec 28, 2005
    #1
    1. Advertising

  2. Lorenzo

    addup Guest

    Your page_Load is missing the handles

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    i.e. it is never being executed
    addup, Dec 28, 2005
    #2
    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. Aaron
    Replies:
    0
    Views:
    382
    Aaron
    Jan 2, 2006
  2. Ray Booysen
    Replies:
    2
    Views:
    631
    Ray Booysen
    Mar 28, 2006
  3. Replies:
    1
    Views:
    354
    Victor Bazarov
    Aug 17, 2006
  4. Replies:
    3
    Views:
    540
    Markus Svilans
    Oct 20, 2006
  5. cms3023
    Replies:
    0
    Views:
    400
    cms3023
    May 20, 2007
Loading...

Share This Page