473,320 Members | 2,098 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,320 software developers and data experts.

How to bind data to DataGrid or Grid View

I have Custom Data class which stores data about single customer and then i
store that customer objects in arraylist as shown below.

Customer custdata = null; // Custom Data class for 1 customer data.

ArrayList ar = new ArrayList(); // To store more than one customer
object.
for (int x = 0; x < 30; x++)
{
custdata = new Customer();
custdata.CustomerID = 1234 + x;
custdata.CustomerName = "Name" + x.ToString();
custdata.CustomerLocation = "UK " + x.ToString();
custdata.CustomerType = x.ToString();

ar.Add(custdata);

}

grid.; /// FEW Steps are missing and not sure to make it compatable to Grid.
grid.DataBind();

Now i want to bind data to gridView control, just like as we do if it was
Datatable.
Is there any simple conversion possible?

I do not want to use DataSet or DataTable but collection of Customer Objects
in Arraylist.

Thanks in advance.
-Vineet
Oct 16 '06 #1
3 9534
Vineet,

The easiest way is to use Eval method. In the code assign grid.DataSource=ar
and in the aspx page use databinding expressions like

<td><%# Eval("Name") %></td>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"vineetbatta" <vi*********@discussions.microsoft.comwrote in message
news:0B**********************************@microsof t.com...
>I have Custom Data class which stores data about single customer and then i
store that customer objects in arraylist as shown below.

Customer custdata = null; // Custom Data class for 1 customer data.

ArrayList ar = new ArrayList(); // To store more than one customer
object.
for (int x = 0; x < 30; x++)
{
custdata = new Customer();
custdata.CustomerID = 1234 + x;
custdata.CustomerName = "Name" + x.ToString();
custdata.CustomerLocation = "UK " + x.ToString();
custdata.CustomerType = x.ToString();

ar.Add(custdata);

}

grid.; /// FEW Steps are missing and not sure to make it compatable to
Grid.
grid.DataBind();

Now i want to bind data to gridView control, just like as we do if it was
Datatable.
Is there any simple conversion possible?

I do not want to use DataSet or DataTable but collection of Customer
Objects
in Arraylist.

Thanks in advance.
-Vineet

Oct 16 '06 #2
Hi Eliyahu,

Is there any way we can use properties like Data member/ Data Key on grid
object just like for DataTable or DataSet?
I want to retain aspx code like

<Columns >
<asp:BoundField DataField = "CustomerID" HeaderText = "ID" />
<asp:BoundField DataField = "CustomerName" HeaderText = "Name" />
<asp:BoundField DataField = "CustomerLocation" HeaderText =
"Location" />
</Columns>

Thanks
"Eliyahu Goldin" wrote:
Vineet,

The easiest way is to use Eval method. In the code assign grid.DataSource=ar
and in the aspx page use databinding expressions like

<td><%# Eval("Name") %></td>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"vineetbatta" <vi*********@discussions.microsoft.comwrote in message
news:0B**********************************@microsof t.com...
I have Custom Data class which stores data about single customer and then i
store that customer objects in arraylist as shown below.

Customer custdata = null; // Custom Data class for 1 customer data.

ArrayList ar = new ArrayList(); // To store more than one customer
object.
for (int x = 0; x < 30; x++)
{
custdata = new Customer();
custdata.CustomerID = 1234 + x;
custdata.CustomerName = "Name" + x.ToString();
custdata.CustomerLocation = "UK " + x.ToString();
custdata.CustomerType = x.ToString();

ar.Add(custdata);

}

grid.; /// FEW Steps are missing and not sure to make it compatable to
Grid.
grid.DataBind();

Now i want to bind data to gridView control, just like as we do if it was
Datatable.
Is there any simple conversion possible?

I do not want to use DataSet or DataTable but collection of Customer
Objects
in Arraylist.

Thanks in advance.
-Vineet


Oct 16 '06 #3
Provided you set grid.DataSource=ar, your example should work.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"vineetbatta" <vi*********@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.com...
Hi Eliyahu,

Is there any way we can use properties like Data member/ Data Key on grid
object just like for DataTable or DataSet?
I want to retain aspx code like

<Columns >
<asp:BoundField DataField = "CustomerID" HeaderText = "ID" />
<asp:BoundField DataField = "CustomerName" HeaderText = "Name" />
<asp:BoundField DataField = "CustomerLocation" HeaderText =
"Location" />
</Columns>

Thanks
"Eliyahu Goldin" wrote:
>Vineet,

The easiest way is to use Eval method. In the code assign
grid.DataSource=ar
and in the aspx page use databinding expressions like

<td><%# Eval("Name") %></td>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"vineetbatta" <vi*********@discussions.microsoft.comwrote in message
news:0B**********************************@microso ft.com...
>I have Custom Data class which stores data about single customer and
then i
store that customer objects in arraylist as shown below.

Customer custdata = null; // Custom Data class for 1 customer data.

ArrayList ar = new ArrayList(); // To store more than one
customer
object.
for (int x = 0; x < 30; x++)
{
custdata = new Customer();
custdata.CustomerID = 1234 + x;
custdata.CustomerName = "Name" + x.ToString();
custdata.CustomerLocation = "UK " + x.ToString();
custdata.CustomerType = x.ToString();

ar.Add(custdata);

}

grid.; /// FEW Steps are missing and not sure to make it compatable to
Grid.
grid.DataBind();

Now i want to bind data to gridView control, just like as we do if it
was
Datatable.
Is there any simple conversion possible?

I do not want to use DataSet or DataTable but collection of Customer
Objects
in Arraylist.

Thanks in advance.
-Vineet



Oct 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
1
by: yaniv abo | last post by:
Hello. How can I bind a list of objects to a DataGird? I have a custom collection of Customer class
6
by: Alpha | last post by:
I have several textboxes that I need to chang the text when the selection row is changed in a datagrid. I have the following code. This textbox displayes the initial selection but when I click on...
0
by: Steve | last post by:
Hi I have a db with 2 tables that I want to bind to a grid depending on a selection in a Dropdownlist Also I want to be able to select a row from the gris to fill some textboxes. The databases...
6
by: coleenholley | last post by:
I have a Class Module written in VB that calls an RPC (written in COBOL) we have written code to read the data from the RPC, and we create a temporary datatable to store the data from the RPC. This...
3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
1
by: gordon | last post by:
Hi I have some standard text book type examples of oleDB connections and routines that populate a list box with data with a query on an Access database. What I would like to do is to use a...
0
by: Amritha.Datta | last post by:
I want to update MDIChild grid control by setting a datasource. How does it possible from parent form? In other words, I have a data grid control on a MDIChild form. I am binding the data source...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.