Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / DataGrid / December 2005

Tip: Looking for answers? Try searching our database.

Help me understand what is wrong (Data not showing)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lorenzo - 28 Dec 2005 17:44 GMT
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
addup - 28 Dec 2005 18:32 GMT
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
saket - 30 Dec 2005 11:22 GMT
hi
 there is abs no erroe in ur code
 may be the hadle of page load event is not defined.
 check wether the page load handle is properly define or not

 this.Load += new System.EventHandler(this.Page_Load);

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.