PDA

View Full Version : [CLOSED] How to create array object in codebehind



Jurke
Oct 09, 2008, 3:58 AM
Hi
Iam trying to create this array from your example site, in the code behind (dynamically). But I have not succeded. Can you please help me with this?





private object[] TestData
{
get
{
DateTime now = DateTime.Now;
return new object[]
{
new object[] {"3m Co", 71.72, 0.02, 0.03, now},
new object[] {"Wal-Mart Stores, Inc.", 45.45, 0.73, 1.63, now}
};
}
}


Best regards
Mikael Jürke

Vladimir
Oct 09, 2008, 5:11 AM
Hi Mikael,

Can you give us more details? Do you have compiler error or something else?

Jurke
Oct 09, 2008, 6:05 AM
Hi
Sorry for beeing unclear, I want to add rows to the object in the pageload like


PageLoad()
{
TestData = new object[] {"Test", "71.72", "0.02", "0.03", ""},
}


Best regards
Mikael Jürke

Vladimir
Oct 09, 2008, 6:10 AM
I don't understand what the problem do you have. If you use array as DataSource then you must use ArrayReader in Store. Can you explain what kind of problem?

May be this example can help you http://examples1.ext.net/#/GridPanel/ArrayGrid/Simple/

Jurke
Oct 09, 2008, 6:30 AM
Yes I know. I want to use an array as datasource and it works great. BUT I want to add the objects dynamically and I dont know how to do that. As my first example the array contains 2 objects with the company names "3m Co" and "Wal-Mart Stores", But I dont know in advance how many objects I have, I want to be able to add theese objects in the page load method like this, but I dont know the syntax.







protected void Page_Load(object sender, EventArgs e)
{
for (int i=0; i<10; i++)
{
TestData = new object[] {"Test"+i, "1", "1", "1", ""},
}
}


Hope you understand what I want to do

Best regards
Mikael Jürke

Vladimir
Oct 09, 2008, 6:58 AM
Thanks for clarifications. An array don't have functionality to add new data (it is a static size structure). I can suggest next solution if you need to add new data to array



object[] data = new object[]
{
new object[] {"3m Co", 71.72, 0.02, 0.03, "9/1 12:00am"},
new object[] {"Wal-Mart Stores, Inc.", 45.45, 0.73, 1.63, "9/1 12:00am"}
};

ArrayList list = new ArrayList(data);

//add new data
list.Add(new object[] {"Wal-Mart Stores, Inc.", 45.45, 0.73, 1.63, "9/1 12:00am"});

this.Store1.DataSource = list.ToArray();
this.Store1.DataBind();


Hope this help

Jurke
Oct 09, 2008, 7:20 AM
Thank you! right on the spot! Works excellent!

Best regards
Mikael Jürke