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/