Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.Net - Arraylist (get and set accessors)

Status
Not open for further replies.

NewFromMattel

Programmer
Jun 24, 2003
41
US
I'm learning .Net (C#) and trying to implement some code in ASP.Net. My goal is to gain understanding by replicating some functions that I can do in coldfusion.

Here's what I'm doing. Building a very basic menuing control so that Default.aspx?index=2 will show a menu tab highlighted, and so on. And the menu tabs are built and driven (by a datalist) from an arraylist. So I initialize the arraylist, and then add items to it via a class that uses get and set accessors (that I don't really understand yet, but I'm trying).

Then I bind the datalist to the arraylist. Then the datalist accesses the elements of the arraylist and derives "Name" and "Path" successfully. I've built this from pieces here and there (especially the quickstart tutorials, and the Time tracker starter kit). But now I'm "freelancing" trying to access the arraylist and get the name out. But I just can't get it. So here's what I've got. (limited the coding pasted to shorten the post)

public MyTabItem(string newName, string newPath) // call the MyTabItem method with the vars
{
_name = newName;
_path = newPath;
}

public string Name
{
get { return _name;}
set { _name = value;}
}

public string Path
{
get { return _path; }
set { _path = value; }
}

thenin the page_load

ArrayList menuItems = new ArrayList();
menuItems.Add(new MyTabItem("Work History", "?index=" + menuItems.Count));
menuItems.Add(new MyTabItem("Past Accomplishments", "?index=" + menuItems.Count));
menuItems.Add(new MyTabItem("References", "?index=" + menuItems.Count));

MyDataList.DataSource = menuItems;
MyDataList.DataBind();

int urlSelection = (Request["index"]==null) ? 0 : Convert.ToInt32(Request["index"]);
MyDataList.SelectedIndex = urlSelection;

here is the datalist guts (the hyperlink control for the actual tab
<asp:HyperLink id=HyperLink1 runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container.DataItem, &quot;Name&quot;) %>' NavigateUrl='<%# Request.Path + DataBinder.Eval(Container.DataItem, &quot;Path&quot;, &quot;{0}&quot;) %>'>
</asp:HyperLink>

Now what I want to do is somewhere else on the page, just have a label and set the text of the label to equal the &quot;Name&quot; of the part of the arraylist element.

This is all a learning process. I've learned a lot thus far, and any help at all will be appreciated.

TIS
NewFromMattell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top