Hi Kjetil,
The ObjectDataSource, in your code below, was using the DataAdapter (which
did not have a definition for the expression column). You needed to fill the
DataTable then bind it to the GridView in order for the expression column to
be used (in the manner you did it), e.g. you needed to add code similar to
this in the CodeFile:
DataSet ds = new DataSet();
DataSetTableAdapters.CustomersTableAdapter adapter1 = new
DataSetTableAdapters.CustomersTableAdapter ();
adapter1.Fill(ds.Customers);
GridView1.DataSource = ds.Customers ;
GridView1.DataBind();
Otherwise, the declarative syntax would have worked, had you defined the new
column in the DataAdapter by modifying the Query:
SELECT CustomerID, ContactName, ContactTitle, ContactTitle+'
'+ContactName as ContactTitleName
FROM Customers
--
HTH,
Phillip Williams
http://www.societopia.net http://www.webswapp.com
"Kjetil Klaussen" wrote:
Hi,
I’m having some troubles trying to bind my dataset to a GridView control
through an ObjectDataSource control. The binding works fine for regular
columns in my dataset, but I can’t seem to get my expression columns to show
up in my GridView. Anybody knows any neat tricks to make this work?
Here’s a “step-by-step” to reproduce my worries:
1. Create a new “ASP.NET web site” project
2. Add the “ASP.NET folder” called “App_Code” and add a dataset to this folder
3. Set up the datatable adapter to select some columns from e.g. the
Northwind Customers table, for instance the “CustomerID”, “ContactName”, and
“ContactTitle” columns.
4. Add a column to the dataset table and call it “ContactTitleName”. Set the
“Expression” property to “ContactTitle + ' ' + ContactName”.
5. Drag an ObjectDataSource control on to a web page
6. Set up the datasource to get data from your newly created dataset
tableadapter
7. Add a GridView control and set it’s datasource to your newly created
ObjectDataSource
8. Run the project
9. All columns except the expression column called “ContactTitleName” are
rendered
--
Sincerely,
Kjetil Klaussen
Application Developer, Trondheim