473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataBind a Two or Multi Dimensional Array to Gridview

12
Can anyone tell me why I am not allowed to bind a two or multi dimensional array to GridView and possibly suggest how they would deal with similar scenarios?

The array is simply a two dimensional monthly volume array:

Extract from Report class:

// Query all Messages Sent for a Given Month
public string[,] qVolumeByMonth()
{
string[,] volumeByMonth = new string[2,13];
SqlCommand comm = Data.getCommand("spVolumeByMonth");
DataTable table = Data.ExecuteQueryCommand(comm);
// Initialise the array month values
for (int months = 0; months < 12; months++)
{
volumeByMonth[0,months] = Convert.ToString(months + 1);
volumeByMonth[1,months] = "0";
}
volumeByMonth[0,12] = "Total";
volumeByMonth[1,12] = "0";
// Enter the database information into the array
int totalMessages = 0;
for (int rows = 0; rows < table.Rows.Count; rows++)
{
volumeByMonth[1,(Convert.ToInt32(table.Rows[rows]["month"].ToString()) - 1)] = table.Rows[rows]["messages"].ToString();
totalMessages += Convert.ToInt32(table.Rows[rows]["messages"].ToString());
}
volumeByMonth[1,12] = totalMessages.ToString();
return volumeByMonth;
}

This all works to provide a simple two dimensional array. Then when I try to bind to GridView with the following code:

Report report = new Report();
string[,] volumeByMonth = report.qVolumeByMonth();
gvVolumeByMonth.DataSource = volumeByMonth;
gvVolumeByMonth.DataBind();

I get the following eror: "Array was not a one-dimensional array."

Can the GridView simply not be bound to multidimensional arrays?

Kind Regards,

Ian
Jun 8 '07 #1
3 18030
Vidhura
99
Can anyone tell me why I am not allowed to bind a two or multi dimensional array to GridView and possibly suggest how they would deal with similar scenarios?

The array is simply a two dimensional monthly volume array:

Extract from Report class:

// Query all Messages Sent for a Given Month
public string[,] qVolumeByMonth()
{
string[,] volumeByMonth = new string[2,13];
SqlCommand comm = Data.getCommand("spVolumeByMonth");
DataTable table = Data.ExecuteQueryCommand(comm);
// Initialise the array month values
for (int months = 0; months < 12; months++)
{
volumeByMonth[0,months] = Convert.ToString(months + 1);
volumeByMonth[1,months] = "0";
}
volumeByMonth[0,12] = "Total";
volumeByMonth[1,12] = "0";
// Enter the database information into the array
int totalMessages = 0;
for (int rows = 0; rows < table.Rows.Count; rows++)
{
volumeByMonth[1,(Convert.ToInt32(table.Rows[rows]["month"].ToString()) - 1)] = table.Rows[rows]["messages"].ToString();
totalMessages += Convert.ToInt32(table.Rows[rows]["messages"].ToString());
}
volumeByMonth[1,12] = totalMessages.ToString();
return volumeByMonth;
}

This all works to provide a simple two dimensional array. Then when I try to bind to GridView with the following code:

Report report = new Report();
string[,] volumeByMonth = report.qVolumeByMonth();
gvVolumeByMonth.DataSource = volumeByMonth;
gvVolumeByMonth.DataBind();

I get the following eror: "Array was not a one-dimensional array."

Can the GridView simply not be bound to multidimensional arrays?

Kind Regards,

Ian
Hope the following helps:
http://forums.microsoft.com/MSDN/Sho...05432&SiteID=1
http://www.devx.com/dotnet/Article/33748
Jun 8 '07 #2
gihope
12
Excellent, I'll give these a try.

Much appreciated!

Ian
Jun 8 '07 #3
gihope
12
That second article was the business and helped me considerably on this and now future projects. Thank You!!

Ian
Jun 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
5
by: Cant Think Today | last post by:
I have multi-dimesional arrays that can be specifed by the user, e.g 1,2,3,4,5 1,2,3,4,5,6,7,8,9,10 1,2,3,4,5,6 I think a bit of code that will iterate over these arrays to print out the...
5
by: Andrew Poulos | last post by:
If I'm searching for an occurance of a value in a multi-dimensional array how can I get it's index returned as an array, if found? For example, if: foo = new Array(); foo = , 5, , 9, 10]; ...
4
by: Robert P. | last post by:
I can easily store a one-dimensional array in viewstate ( see Test1 ) If I try storing a multi-dimensional array in the viewstate it's crapping out on me when it goes to serialize the array (not...
4
by: entitledX | last post by:
Hi, I'm trying to use the HDF library to read a few HDF files that I need to process. The data in each file varies in rows, but the columns remain constant. Because of that, I had dynamically...
4
by: Balaskas Evaggelos | last post by:
Hi, does anyone know how i can sort a multi-dimensional array by a specific field ? for example i want to sort arr where n=2, but i need the data of every array to follow that order. ...
11
by: gianluca | last post by:
Hy list, I've to declare a 3D matrix in C . I tried with that code: double ***mat; mat=(double***)G_malloc(ndimension*(sizeof(double)); but the program send me a run time error.
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
4
by: =?Utf-8?B?SGVucmlrIFNjaG1pZA==?= | last post by:
Hi, consider the attached code. Serializing the multi-dimensional array takes about 36s vs. 0.36s for the single-dimensional array. Initializing the multi-dimensional array takes about 4s...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.