Hi I am using VS2008. I am new to asp and of course I'm touring the web for examples to help with my learning. I wanted to set a repeaters datasource via an array. So, found numerous examples, downloaded (copiied) set them up and wham NONE worked. Afte 3
dayas of frustrarion an confusion I switched to c#, downloaded examples and THEY worked; so I then converted the code to VB, and yep, they didn't work. I'm really having trouble working out why this should be.
vb...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim a As Integer() = New Integer(9) {}
Dim count As Integer = 10
For i As Integer = 0 To 9
a(i) = count
count += 10
Next
DataList1.DataSource = a
DataList1.DataBind()
End Sub
c#
protected void Page_Load(object sender, EventArgs e)
{
int[] a = new int[10];
int count = 10;
for (int i = 0; i < 10; i++)
{
a[i] = count;
count += 10;
}
result.DataSource = a;
result.DataBind();
}
Repeaters are the same:
<div>
<asp:Repeater ID="result" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" Text='<%#Container.DataItem %>' runat="server"></asp:Label>
<br />
</ItemTemplate>
</asp:Repeater>
</div>
I'm using System.Data namespace
Any Ideas. Is is something which can't be done in VB?
Thank you for your time;
Hi Thanks. That is my point, I believe it to be ok, but when I render the page via VS2008, it is blank, but when I render the c# version it runs and I am at a loss as too why. I am assuming it is something within the VS2008 assembly which might have got
corrupted? So, just to try this I uploaded tha page onto my server and it returns blank there too. So maybe I might be missing a namespace or something like that, but for the life of me I can't see what?
Opps meant to say ref the Datalist1. Yep, I actually tried it on the Repeater and then a Datalist, meant to copy up the Datalist construct, sorry about that, as you say just change to a repeater, repeater1
Hi, Thanks. I placed both the c# version and the vb version here to try to illustrate my point. In the above instance the VB was converted from the C#, and then it displayed the results ok.
My problem is not just with this example, I have a further 32 examples where the VB code returns a blank page, while the converted to c# version renders the results ok? The 32 examples are pretty simpleand were copied off various sites and from a number
of books, I'm including Microsoft MSDN pages and W3 School and so on. None of them render a result if run in VB.
If I convert the same examples from vb to c# then the examples work but not, as I explained, if I use VB. With VB all I get are blank pages?
I must be missing some namespace declaration maybe? But I just cannot see which one that would be. I'm using System.Data but I have also tried a myriad of others 'just in case'. for example
Whatever I do only the C# versions render. I did think it might be something in VS2008 but I posted a couple of examples online and they still didn't render.
Thanks again. having read up on this aspect now, I noticed that for Visual Studio development it is advised that the autowire be set to false to avoid 'double' firing of certain events. So, the other wor around is to add a handler which my page load was
missing, setting autowire back to false and adding Handles Me.load aslo sorted the very stupid beginners error. THanks agaion . without your comment I would not have been set off on the right track. So, regards again.
RayH1955
Member
99 Points
42 Posts
repeater array data source VB doesnt render C# does?
May 22, 2011 01:30 PM|LINK
Hi I am using VS2008. I am new to asp and of course I'm touring the web for examples to help with my learning. I wanted to set a repeaters datasource via an array. So, found numerous examples, downloaded (copiied) set them up and wham NONE worked. Afte 3 dayas of frustrarion an confusion I switched to c#, downloaded examples and THEY worked; so I then converted the code to VB, and yep, they didn't work. I'm really having trouble working out why this should be.
vb...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim a As Integer() = New Integer(9) {} Dim count As Integer = 10 For i As Integer = 0 To 9 a(i) = count count += 10 Next DataList1.DataSource = a DataList1.DataBind() End Sub c# protected void Page_Load(object sender, EventArgs e) { int[] a = new int[10]; int count = 10; for (int i = 0; i < 10; i++) { a[i] = count; count += 10; } result.DataSource = a; result.DataBind(); } Repeaters are the same: <div> <asp:Repeater ID="result" runat="server"> <ItemTemplate> <asp:Label ID="Label1" Text='<%#Container.DataItem %>' runat="server"></asp:Label> <br /> </ItemTemplate> </asp:Repeater> </div> I'm using System.Data namespace Any Ideas. Is is something which can't be done in VB? Thank you for your time;Jos Branders
Contributor
5210 Points
822 Posts
Re: repeater array data source VB doesnt render C# does?
May 22, 2011 04:55 PM|LINK
Your VB code runs fine with me.
I just had to change DataList1 to result (that's the ID of your repeater).
Jos
RayH1955
Member
99 Points
42 Posts
Re: repeater array data source VB doesnt render C# does?
May 22, 2011 10:32 PM|LINK
Hi Thanks. That is my point, I believe it to be ok, but when I render the page via VS2008, it is blank, but when I render the c# version it runs and I am at a loss as too why. I am assuming it is something within the VS2008 assembly which might have got corrupted? So, just to try this I uploaded tha page onto my server and it returns blank there too. So maybe I might be missing a namespace or something like that, but for the life of me I can't see what?
RayH1955
Member
99 Points
42 Posts
Re: repeater array data source VB doesnt render C# does?
May 22, 2011 10:38 PM|LINK
Opps meant to say ref the Datalist1. Yep, I actually tried it on the Repeater and then a Datalist, meant to copy up the Datalist construct, sorry about that, as you say just change to a repeater, repeater1
Regard
WombatEd
Contributor
4098 Points
1059 Posts
Re: repeater array data source VB doesnt render C# does?
May 23, 2011 02:03 AM|LINK
If your markup is identical, you might try a C# to VB converter:
(Assuming that isn't how you converted it in the first place... ;-)
If I give you a useful answer, please click the ANSWER button. (Please do this for ALL posts that are really useful.)
RayH1955
Member
99 Points
42 Posts
Re: repeater array data source VB doesnt render C# does?
May 23, 2011 10:01 AM|LINK
Hi, Thanks. I placed both the c# version and the vb version here to try to illustrate my point. In the above instance the VB was converted from the C#, and then it displayed the results ok.
My problem is not just with this example, I have a further 32 examples where the VB code returns a blank page, while the converted to c# version renders the results ok? The 32 examples are pretty simpleand were copied off various sites and from a number of books, I'm including Microsoft MSDN pages and W3 School and so on. None of them render a result if run in VB.
If I convert the same examples from vb to c# then the examples work but not, as I explained, if I use VB. With VB all I get are blank pages?
I must be missing some namespace declaration maybe? But I just cannot see which one that would be. I'm using System.Data but I have also tried a myriad of others 'just in case'. for example
System.Configuration, Web, Web.Security, Web.UI, Web.UI.Control, Web.UI.Control.WebParts, UI.HtmlControls, Collections.Generic, Data.SqlClient, Data.Common and lastly System.
Whatever I do only the C# versions render. I did think it might be something in VS2008 but I posted a couple of examples online and they still didn't render.
Shakti Singh...
Star
10870 Points
1827 Posts
Re: repeater array data source VB doesnt render C# does?
May 23, 2011 10:20 AM|LINK
This is because of different page directives in VB and C#
Here is VB.... culprit is in bold.. By default AutoEventWireup is false in VB.Net so your events never fire. Just change this to true
Need to change as
Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
RayH1955
Member
99 Points
42 Posts
Re: repeater array data source VB doesnt render C# does?
May 23, 2011 10:44 AM|LINK
Thank you, you are a star. No matter how much I stared I would not have noticed that, lol.!"!!!!
Thank you again, it was just what I needed, hahahahaha
RayH1955
Member
99 Points
42 Posts
Re: repeater array data source VB doesnt render C# does?
May 23, 2011 11:09 AM|LINK
Thanks again. having read up on this aspect now, I noticed that for Visual Studio development it is advised that the autowire be set to false to avoid 'double' firing of certain events. So, the other wor around is to add a handler which my page load was missing, setting autowire back to false and adding Handles Me.load aslo sorted the very stupid beginners error. THanks agaion . without your comment I would not have been set off on the right track. So, regards again.