L
Lorenzo
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
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