470,631 Members | 1,621 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

datagrid and array

hi guys, my code is returning an array and i need to create datagrid so that
i can have sorting and implement prev....next function on it to navigate. is
there any way this can be done in codebehind file. I am using c#.

Thanks
Manny
Nov 18 '05 #1
4 1983
Manny Chohan wrote:
hi guys, my code is returning an array and i need to create datagrid so that
i can have sorting and implement prev....next function on it to navigate. is
there any way this can be done in codebehind file. I am using c#.


What does your array contain? Just simple, primitive types (int,
string, etc.), or complex classes with properties? If it's the former,
read this article:

Binding a Scalar Array to a Data Web Control
http://aspnet.4guysfromrolla.com/articles/082504-1.aspx

If it's the latter, check out:

Displaying Custom Classes in a DataGrid
http://aspnet.4guysfromrolla.com/articles/102302-1.aspx

Once you have the data bound to the DataGrid, you can use the DataGrid's
sorting, paging, etc. features to implement the sorting and paging and
any other features you need. There's a ton of good DataGrid information
(including info on sorting and paging) in this 16-part articles series:

An Extensive Examination of the DataGrid Web Control
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #2
Hi Scott,

can this be done to datagrid if i need to bind it to array:
DataGrid1.DataSource(allRecords("1").ToString(),al lRecords("2").ToString(),allRecords("3").ToString( ));
Manny Singh

"Scott Mitchell [MVP]" wrote:
Manny Chohan wrote:
hi guys, my code is returning an array and i need to create datagrid so that
i can have sorting and implement prev....next function on it to navigate. is
there any way this can be done in codebehind file. I am using c#.


What does your array contain? Just simple, primitive types (int,
string, etc.), or complex classes with properties? If it's the former,
read this article:

Binding a Scalar Array to a Data Web Control
http://aspnet.4guysfromrolla.com/articles/082504-1.aspx

If it's the latter, check out:

Displaying Custom Classes in a DataGrid
http://aspnet.4guysfromrolla.com/articles/102302-1.aspx

Once you have the data bound to the DataGrid, you can use the DataGrid's
sorting, paging, etc. features to implement the sorting and paging and
any other features you need. There's a ton of good DataGrid information
(including info on sorting and paging) in this 16-part articles series:

An Extensive Examination of the DataGrid Web Control
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

Nov 18 '05 #3
Your syntax looks a little weird, but, sure, you could create a string
array, populate it with the values, and then bind the string array to
the grid. The code might look like:

ArrayList s = new ArrayList();
s.Add(allRecords("1").ToString());
s.Add(allRecords("2").ToString());
....

DataGrid1.DataSource = s.ToArray(typeof(string));
DataGrid1.DataBind();
That ought to work.
Manny Chohan wrote:
Hi Scott,

can this be done to datagrid if i need to bind it to array:
DataGrid1.DataSource(allRecords("1").ToString(),al lRecords("2").ToString(),allRecords("3").ToString( ));
Manny Singh

"Scott Mitchell [MVP]" wrote:

Manny Chohan wrote:
hi guys, my code is returning an array and i need to create datagrid so that
i can have sorting and implement prev....next function on it to navigate. is
there any way this can be done in codebehind file. I am using c#.


What does your array contain? Just simple, primitive types (int,
string, etc.), or complex classes with properties? If it's the former,
read this article:

Binding a Scalar Array to a Data Web Control
http://aspnet.4guysfromrolla.com/articles/082504-1.aspx

If it's the latter, check out:

Displaying Custom Classes in a DataGrid
http://aspnet.4guysfromrolla.com/articles/102302-1.aspx

Once you have the data bound to the DataGrid, you can use the DataGrid's
sorting, paging, etc. features to implement the sorting and paging and
any other features you need. There's a ton of good DataGrid information
(including info on sorting and paging) in this 16-part articles series:

An Extensive Examination of the DataGrid Web Control
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #4
Sorry Scott, i just found out that the array is a two dimensional array
arrlist[i,z]. Do you have any code that addresses this issue?

Manny

"Scott Mitchell [MVP]" wrote:
Your syntax looks a little weird, but, sure, you could create a string
array, populate it with the values, and then bind the string array to
the grid. The code might look like:

ArrayList s = new ArrayList();
s.Add(allRecords("1").ToString());
s.Add(allRecords("2").ToString());
....

DataGrid1.DataSource = s.ToArray(typeof(string));
DataGrid1.DataBind();
That ought to work.
Manny Chohan wrote:
Hi Scott,

can this be done to datagrid if i need to bind it to array:
DataGrid1.DataSource(allRecords("1").ToString(),al lRecords("2").ToString(),allRecords("3").ToString( ));
Manny Singh

"Scott Mitchell [MVP]" wrote:

Manny Chohan wrote:

hi guys, my code is returning an array and i need to create datagrid so that
i can have sorting and implement prev....next function on it to navigate. is
there any way this can be done in codebehind file. I am using c#.

What does your array contain? Just simple, primitive types (int,
string, etc.), or complex classes with properties? If it's the former,
read this article:

Binding a Scalar Array to a Data Web Control
http://aspnet.4guysfromrolla.com/articles/082504-1.aspx

If it's the latter, check out:

Displaying Custom Classes in a DataGrid
http://aspnet.4guysfromrolla.com/articles/102302-1.aspx

Once you have the data bound to the DataGrid, you can use the DataGrid's
sorting, paging, etc. features to implement the sorting and paging and
any other features you need. There's a ton of good DataGrid information
(including info on sorting and paging) in this 16-part articles series:

An Extensive Examination of the DataGrid Web Control
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by serge calderara | last post: by
2 posts views Thread by Chris Plowman | last post: by
reply views Thread by Nic | last post: by
5 posts views Thread by DKC | last post: by
5 posts views Thread by rn5a | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.