Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to reference the array "column" into a datalist??

Posted on 2004-08-27
7
Medium Priority
?
234 Views
Last Modified: 2010-04-15

Hello, new to .NET. I'm using a class to populate an array from a dataset (I know a dataset is an array, but I have to do some other stuff) and I can't figure out how to set which "column" from the array to display when I bind it to a DataList. Since my ArrayList doesn't have column names, I can't use this syntax:

# DataBinder.Eval(Container.DataItem, "column1")

And I thought I could do this:

# DataBinder.Eval(Container.DataItem, "Item[2]")
or
# DataBinder.Eval(Container.DataItem, Item[2])

But that doesn't work either. If I do this: # Container.DataItem...it spits out the whole array, which looks like:

id, my name, my company

How do you reference a specific ordinal out of the arraylist in the datalist?

This is how I'm building my array, perhaps something is wrong here:

public void Add(DataRow dr)
{
   _ID = IncrementID();
   _RecipientName = dr["Recipient Name"].ToString();
   _Company = dr["Company"].ToString();
   Info.Add(string.Concat(S_ID, ", ", RecipientName, ", ", Company));
}

thanks in advance!!
0
Comment
Question by:animated405
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:Thogek
ID: 11915073
I'm guessing that Info is your System.Collections.ArrayList instance...

    Info.Add(string.Concat(S_ID, ", ", RecipientName, ", ", Company));

This is concatenating your S_ID, RecipientName, and Company strings into one string, and adding that string as a member of the Info ArrayList.  (In which case the "id, my name, my company" output sounds right.)  Is that what you meant to do?
0
 
LVL 15

Expert Comment

by:Thogek
ID: 11915107
If you need to keep track of your columns separately, then maybe you need three separate ArrayLists?

    InfoID.Add(_ID);
    InfoRecipient.Add(_RecipientName );
    InfoCompany.Add(_Company);

Then bind to whichever one you need at the time.
0
 

Author Comment

by:animated405
ID: 11915324

thanks for the reply. I don't want to have more than one array. What I was doing originally was just looping through the datarows and adding each one to an array and instanciating a class each time through as well. so I had this:

arArray = new ArrayList();
foreach(DataRow dr in myDataSet.Tables[0].Rows)
{
MyObject myO = new MyObject();
myO.RecipientName = dr["Recipient Name"].ToString();
myO.Company = dr["Company"].ToString();
arArray.Add(myO);
}

this worked fine, I could bind that to a grid as I would expect. So, I thought to make that code cleaner I could just build the array at the same time as I instantiate by calling the class method I added which I will list again:

public void Add(DataRow dr)
{
   _ID = IncrementID();
   _RecipientName = dr["Recipient Name"].ToString();
   _Company = dr["Company"].ToString();
   Info.Add(string.Concat(S_ID, ", ", RecipientName, ", ", Company));
}

But, your right, I'm basically just getting a comma delimited one dimensional array here aren't I? How can I change this so that it will populate the array like I was doing originally. It would be nice to be able to just call MyClass.Info to return the entire array, code would be cleaner that way because I would have all that extra stuff on each page everytime I wanted do that.

thanks again
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 15

Accepted Solution

by:
Thogek earned 2000 total points
ID: 11916616
I'm not sure I understand the full question, but to attempt to meld your two methods together...

    public void Add(DataRow dr)
    {
        _ID = IncrementID();
        _RecipientName = dr["Recipient Name"].ToString();
        _Company = dr["Company"].ToString();

        MyObject myO = new MyObject();
        myO.ID = _ID;  // Not sure if this is how your IDs generate
        myO.RecipientName = _RecipientName;
        myO.Company = _Company;

        _alInfo.Add(myO);
    }

    public ArrayList Info
    {
        get { return _alInfo; }
    }
0
 

Author Comment

by:animated405
ID: 11917102

I'm sorry, but I don't think I'm explaining myself well enough. I see how that works if I'm instatiating a class and adding to the array within that same page. But what I'm trying to do is, while looping through the dataset, instantiate the class, call the classes Add method by passing in the datarow, which in turn inside that class will add another object to a multidemisional array that I can reference by calling that from the class.

So, if in the class my multidimesional array called thisArr, then I would want to be able to call it from the other page and bind it to a grid like so

DataList.Source = MyClass.thisArr;

I guess the problem I'm having is just how to you add to a multidimensional array? thanks again
0
 

Author Comment

by:animated405
ID: 11918084

hey Thogek, thanks for the replies....I managed to get the array working as I intended, however maybe you know the answer to other part of my original question....

now that I have the array, then I bind it to the datalist, what syntax is used in the aspx page in the itemtemplate for accessing the "column" from the array. Since there are no column names with the array, I figured you could refernce it my [0] or something but that doesn't work...

thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question