datagrid and array

G

Guest

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
 
S

Scott Mitchell [MVP]

Manny said:
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
(e-mail address removed)
http://www.4GuysFromRolla.com

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

Guest

Hi Scott,

can this be done to datagrid if i need to bind it to array:


DataGrid1.DataSource(allRecords("1").ToString(),allRecords("2").ToString(),allRecords("3").ToString());


Manny Singh
 
S

Scott Mitchell [MVP]

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 said:
Hi Scott,

can this be done to datagrid if i need to bind it to array:


DataGrid1.DataSource(allRecords("1").ToString(),allRecords("2").ToString(),allRecords("3").ToString());


Manny Singh

:


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

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

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top