Binding to bound columns

R

Russ

I've been trying to figure out how to use the design time column
creation of columns. I turn off AutoGenerateColumns and create the
bound columns in the designer. But how the heck do I get the data
into the grid? All the examples I have seen use a DataTable and add
the columns and rows to it. But what do you do if the columns are
already created? I tried creating the data table anyway and binding
to it, but it was ignored.

I have an ArrayList that contains a number of class instances, each of
which need to be a row in the grid. Each class instance has one
string (name), and two doubles (amounts). The datagrid columns are
"Name", "Amount1", "Amount2". How to bind this data?

The reason I need to use the bound columns is that I want to use
Template Columns so I can make the amounts directly editable in the
grid. But I figured I would first try to see if I can get the data
displayed in a bound column before I try to tackle the Template stuff.

Thanks for any help,

Russ
 
C

Chris S

I've been trying to figure out how to use the design time column
creation of columns. I turn off AutoGenerateColumns and create the
bound columns in the designer. But how the heck do I get the data
into the grid? All the examples I have seen use a DataTable and add
the columns and rows to it. But what do you do if the columns are
already created? I tried creating the data table anyway and binding
to it, but it was ignored.

I have an ArrayList that contains a number of class instances, each of
which need to be a row in the grid. Each class instance has one
string (name), and two doubles (amounts). The datagrid columns are
"Name", "Amount1", "Amount2". How to bind this data?

The reason I need to use the bound columns is that I want to use
Template Columns so I can make the amounts directly editable in the
grid. But I figured I would first try to see if I can get the data
displayed in a bound column before I try to tackle the Template stuff.

Thanks for any help,

Russ

Did you try binding the ArrayList to the Grid and then specifying the
class attributes in the bound column?

(in Page_Load)

myGrid.DataSource = myArrayList;
myGrid.DataBind();


(in Grid Property Builder)

Column1
Text Field: Name

Column2
Text Field: Amount1

....
 
R

Russ

Chris, thanks for answering. The problem is that the data is in an
ArrayList, not in discrete variables. So I would have to specify
something like Ed.Name and Ed.Amount1, etc. But the class instance
named Ed does not even exist yet at design time, so how can it be
specified? The class instance doesn't exist until after the call to
the Web Service, which retrieves a class that contains an ArrayList
containing instances of the EmpData class. So:

EmpData Ed = (EmpData) List [0];

Now I want to bind to Ed, but the only way to do that is to allow the
DataGrid to autogenerate. If I specify in the design time to bind to
Ed.Name, I get a compile error saying Ed is undefined.

I did solve the problem by using the ItemDataBound event and manually
handing each item, but I think there should be a less processor
intensive way to do this.

Thanks again for your answer.

Russ
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top