Solved

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

Posted on 2004-08-27
7
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Accepted Solution

by:
Thogek earned 500 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

Industry Leaders: 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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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