473,811 Members | 3,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with following code

-D-
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.EventArg s) Handles MyBase.Load
Dim MenuItems As New ArrayList

MenuItems.Add(N ew PositionData("A bout Us", "About.aspx "))
MenuItems.Add(N ew PositionData("C ontact Us", "Contact.aspx") )
MenuItems.Add(N ew PositionData("C ustomer Support", "Support.aspx") )
MenuItems.Add(N ew PositionData("S ite Map", "sitemap.aspx") )

Repeater1.DataS ource = MenuItems
Repeater1.DataB ind()
End Sub

Any help is appreciated.
Jun 24 '06 #1
4 1454
> I'm new to .net and just learning c#.

I have the following code in vb and want to convert this to c# <code snipped> Any help is appreciated.


The code is pretty similar in either language:

'*** Untested:
public class PositionData {
private string strText;
private string strUrl;

public PositionData(st ring 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(objec t sender, EventArgs e) {
ArrayList MenuItems = new ArrayList();

MenuItems.Add(n ew PositionData("A bout Us", "About.aspx "));
MenuItems.Add(n ew PositionData("C ontact Us", "Contact.aspx") );
MenuItems.Add(n ew PositionData("C ustomer Support", "Support.aspx") );
MenuItems.Add(n ew PositionData("S ite Map", "sitemap.aspx") );

Repeater1.DataS ource = MenuItems;
Repeater1.DataB ind();
}
'***

Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Jun 24 '06 #2
The first function is

public class PositionData
{
private string strText;
private string strUrl;

public PositionData ( string strDisplayText, string strURL )
{
this.strText = strDisplayText; // this. is not required
strUrl = strURL;
}

public string DisplayText
{
get
{
return strText;
}
}

// ditto other property
}

I'll leave the second function to you or someone else
-D- wrote:
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.EventArg s) Handles MyBase.Load
Dim MenuItems As New ArrayList

MenuItems.Add(N ew PositionData("A bout Us", "About.aspx "))
MenuItems.Add(N ew PositionData("C ontact Us", "Contact.aspx") )
MenuItems.Add(N ew PositionData("C ustomer Support", "Support.aspx") )
MenuItems.Add(N ew PositionData("S ite Map", "sitemap.aspx") )

Repeater1.DataS ource = MenuItems
Repeater1.DataB ind()
End Sub

Any help is appreciated.

Jun 24 '06 #3
-D-
Thanks Mike...I appreciate your help. That got it working.

If I may ask a couple of follow-up questions.

Here is how my code-behind looks:

namespace compass.user_co ntrols

{

using System;

using System.Collecti ons;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.UI.W ebControls;

using System.Web.UI.H tmlControls;

/// <summary>

/// Summary description for TopNavBar.

/// </summary>

public class TopNavBar : System.Web.UI.U serControl

{

protected System.Web.UI.W ebControls.Repe ater Repeater1;
public class PositionData

{

private string strText;

private string strUrl;

public PositionData(st ring 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(objec t sender, System.EventArg s e)

{

// Put user code to initialize the page here

ArrayList MenuItems = new ArrayList();

MenuItems.Add(n ew PositionData("A bout Us", "About.aspx "));

MenuItems.Add(n ew PositionData("C ontact Us", "Contact.aspx") );

MenuItems.Add(n ew PositionData("C ustomer Support", "Support.aspx") );

MenuItems.Add(n ew PositionData("S ite Map", "sitemap.aspx") );

Repeater1.DataS ource = MenuItems;

Repeater1.DataB ind();

}

#region Web Form Designer generated code

override protected void OnInit(EventArg s e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeCompo nent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeCompo nent()

{

this.Load += new System.EventHan dler(this.Page_ Load);

}

#endregion

}

}

forgive my novice quesitons, but first, is there a better way to write this
code? Should I create a class file instead with the property definitions
and method? What that be cleaner or a better way to code this?

why does a new class have to be added for the PositionData method and
properties? I thought I could have used the public class TopNavBar? Or, do
I need to create a new class for every new object that I create?

public class TopNavBar : System.Web.UI.U serControl

{

protected System.Web.UI.W ebControls.Repe ater Repeater1;
public class PositionData

{

private string strText;

private string strUrl;

public PositionData(st ring strDisplayText, string strURL)

{

this.strText = strDisplayText;

this.strUrl = strURL;

}

public string DisplayText

{

get { return strText; }

}

public string URL

{

get { return strUrl; }

}

finally, instead of populaing the arraylist with hardcoded values, I want
populate the values from a database. That is my next step. I assume I
should be using the databind in place of the hard-coded values and a
function that will return the records from the database.

Thanks again.

Regards,

-D-

"Mike D Sutton" <ED***@mvps.org > wrote in message
news:OL******** ******@TK2MSFTN GP03.phx.gbl...
I'm new to .net and just learning c#.

I have the following code in vb and want to convert this to c#

<code snipped>
Any help is appreciated.


The code is pretty similar in either language:

'*** Untested:
public class PositionData {
private string strText;
private string strUrl;

public PositionData(st ring 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(objec t sender, EventArgs e) {
ArrayList MenuItems = new ArrayList();

MenuItems.Add(n ew PositionData("A bout Us", "About.aspx "));
MenuItems.Add(n ew PositionData("C ontact Us", "Contact.aspx") );
MenuItems.Add(n ew PositionData("C ustomer Support", "Support.aspx") );
MenuItems.Add(n ew PositionData("S ite Map", "sitemap.aspx") );

Repeater1.DataS ource = MenuItems;
Repeater1.DataB ind();
}
'***

Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/

Jun 24 '06 #4
Try this page
http://www.carlosag.net/Tools/CodeTr...r/Default.aspx

"-D-" <so*****@NOSPAM .com> wrote in message
news:e7******** ******@TK2MSFTN GP03.phx.gbl...
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.EventArg s) Handles MyBase.Load
Dim MenuItems As New ArrayList

MenuItems.Add(N ew PositionData("A bout Us", "About.aspx "))
MenuItems.Add(N ew PositionData("C ontact Us", "Contact.aspx") )
MenuItems.Add(N ew PositionData("C ustomer Support", "Support.aspx") )
MenuItems.Add(N ew PositionData("S ite Map", "sitemap.aspx") )

Repeater1.DataS ource = MenuItems
Repeater1.DataB ind()
End Sub

Any help is appreciated.

Jun 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2155
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator=' in '*this = CTest::operator+(CTest&)((+t2))' test2.cpp:49: error: candidates are: CTest CTest::operator=(CTest&) make: *** Error 1
0
2160
by: xixi | last post by:
we are using db2 udb v8.1 on win 64 bit with fp3 with type 4 db2jcc.jar driver. such error generated , please help me understand this , thanks 2004-01-12-14.09.02.400000 Instance:DB2 Node:000 PID:1788(db2syscs.exe) TID:980 Appid:none DRDA Application Server sqljsCleanup Probe:60 DIA0001E An internal error occurred. Report the following error code : "ZRC=0xFFFFFBF6".
3
6324
by: ChrisWinterscheid | last post by:
We are running DB2 8.1 on AIX 5.2. DB2level shows: DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL08016" with level identifier "02070106". Informational tokens are "DB2 v8.1.1.56", "s040616", "U497635", and FixPak "6". Product is installed at "/usr/opt/db2_08_01".
6
391
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and hides all of them including hiding the database window, disabling menu changes. What I am after is the same effect as disabling all the check boxes in startup which still leaves 'File', 'Edit', 'Insert','Records','Window' &'Help'. I want to do this...
7
3312
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
0
1899
by: john | last post by:
Hi,All MS Tech Gurus: I need your help!!! It is the second time I post this message, I need get some feedback ASAP, Please Help!! Thanks a lot in advance. John I have a csharp method, using emit to dynamically generate classes & method depends on the meta table in the database,here is my situation 1) In One method I generated the code Dynamic IL Code (Depends on the data pass to it), The generated code works for one dataset but does...
1
1823
by: Robert | last post by:
Vb.Net Make dll that contain one function. Help Please. I would like to call a function from different applications. I think i have to make a dll. I have Visual Basic.net 2003 Standard Edition, that teorically does not make dll, but pratically does. I search vbc.exe and copy it to a new folder, in which i have the
12
3583
by: What the Hell? | last post by:
I have a question for people out there, I need the Combobox to change a label caption when the user picks a certain thing from the list. How do I code this. I've tried an If Then statement, but it doesn't seem to work. Somebody please help!
12
2482
by: =?Utf-8?B?ZGdvdw==?= | last post by:
I designed a "contact_us" page in visual web developer 2005 express along with EW2 after viewing tutorials on asp.net's help page. Features work like they should, but I cannot figure out how to send contact info to email or data base when the "send" button is pressed. I've watched the tutorials over & over again. I just can't get it. Link: http://www.syfloristonline.zipa.com/contact_us.aspx. Need help
2
10051
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name is used to access and read the value stored in it C.A variable is allocated or deallocated in memory during runtime D.A variable can be initialized at the time of its creation or later 2. The.……types feature facilitates the definition of classes...
0
9724
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10394
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7665
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4336
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.