I'm new to .net and just learning c#.
I have the following code in vb and want to convert this to c#
Public Class PositionData
Private strText As String
Private strUrl As String
Public Sub New(ByVal strDisplayText As String, ByVal strURL As String)
Me.strText = strDisplayText
Me.strUrl = strURL
End Sub
Public ReadOnly Property DisplayText() As String
Get
Return strText
End Get
End Property
Public ReadOnly Property URL() As String
Get
Return strUrl
End Get
End Property
End Class
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim MenuItems As New ArrayList
MenuItems.Add(New PositionData("About Us", "About.aspx"))
MenuItems.Add(New PositionData("Contact Us", "Contact.aspx"))
MenuItems.Add(New PositionData("Customer Support", "Support.aspx"))
MenuItems.Add(New PositionData("Site Map", "sitemap.aspx"))
Repeater1.DataSource = MenuItems
Repeater1.DataBind()
End Sub
Any help is appreciated.

help with the following code
stephenl
Thanks for replying to my post. I appreciate the help and information.
I'm just learning asp.net and object oriented programming. I had a couple of questions regarding the code I wrote below.
Here is the control:
<ul>
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<li><a href='<%# DataBinder.Eval(Container.DataItem, "URL") %>'><%# DataBinder.Eval(Container.DataItem, "DisplayText") %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
Here is the code-behind:
namespace compass.user_controls
{
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for TopNavBar.
/// </summary>
public class TopNavBar : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Repeater Repeater1;
public class PositionData
{
private string strText;
private string strUrl;
public PositionData(string strDisplayText, string strURL)
{
this.strText = strDisplayText;
this.strUrl = strURL;
}
public string DisplayText
{
get { return strText; }
}
public string URL
{
get { return strUrl; }
}
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
ArrayList MenuItems = new ArrayList();
MenuItems.Add(new PositionData("About Us", "About.aspx"));
MenuItems.Add(new PositionData("Contact Us", "Contact.aspx"));
MenuItems.Add(new PositionData("Customer Support", "Support.aspx"));
MenuItems.Add(new PositionData("Site Map", "sitemap.aspx"));
Repeater1.DataSource = MenuItems;
Repeater1.DataBind();
}
}
}
Do I need to create a new class for every new object that I create I thought I could use the 'TopNavBar' class to define the properties and method I have listed in the 'PositionData' class. Why is it necessary to define the new class 'PositionData' to declare the properties and method Would it be more efficient to create a seperate class file to define these properties and methods and reference the class file in the code-behind file. If so, how would I reference the the class file method and properties in the code-behind file
The main question I had is why I needed to define the new class 'PositionData' to define the properties and method.
My next step is to dynamically populate the arraylist from a database table instead of using hard-coded values.
I'm just trying to get a better understanding on the fundamentals of the code.
Thanks again for the help.
Regards,
-D-
DeveloperFrankie
of note. . . a difference between vb and csharp:
C-Sharp does not suppport declarative event handling, you have to explicitly set the handler with a += operation.
This is actually a good thing. . . I was enlightened to the fact that VB's declarative event handling is a major performance hog. not a big thing in winforms, but in web apps, it can cause a performance issue.
in this case, you can override OnLoad (the preferred method of doing it):
private override void OnLoad(System.EventArgs e)
{
base.OnLoad(e);
ArrayList MenuItems = new ArrayList();
MenuItems.Add(new PositionData("About Us", "About.aspx"));
MenuItems.Add(new PositionData("Contact Us", "Contact.aspx"));
MenuItems.Add(new PositionData("Customer Support", "Support.aspx"));
MenuItems.Add(new PositionData("Site Map", "sitemap.aspx"));
//Repeater1.DataSource = MenuItems;
//Repeater1.DataBind();
}
Satish33
If you want to accomplish this easily download Lutz Roeder's Reflector from this site:
http://www.aisto.com/roeder/dotnet/
You can view an assembly (ddll/exe) and choose the language to display it in (C# VB Delphi IL) and just copy that.
Thus if you write a program in VB and wonder what it would look like in C#, you can do so very easily.
Juliano.net
using System.Collections;
public class PositionData
{
private string strText;
private string strUrl;
public PositionData(string strDisplayText, string strURL)
{
this.strText = strDisplayText;
this.strUrl = strURL;
}
public string DisplayText
{
get
{
return strText;
}
}
public string URL
{
get
{
return strUrl;
}
}
}
private void Page_Load(System.Object sender, System.EventArgs e)
{
ArrayList MenuItems = new ArrayList();
MenuItems.Add(new PositionData("About Us", "About.aspx"));
MenuItems.Add(new PositionData("Contact Us", "Contact.aspx"));
MenuItems.Add(new PositionData("Customer Support", "Support.aspx"));
MenuItems.Add(new PositionData("Site Map", "sitemap.aspx"));
//Repeater1.DataSource = MenuItems;
//Repeater1.DataBind();
}