469,327 Members | 1,323 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

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 17718
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

Post your reply

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

Similar topics

5 posts views Thread by Cant Think Today | last post: by
5 posts views Thread by Andrew Poulos | last post: by
4 posts views Thread by Balaskas Evaggelos | last post: by
11 posts views Thread by gianluca | last post: by
4 posts views Thread by =?Utf-8?B?SGVucmlrIFNjaG1pZA==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.