How to add a property to a Table Adapter that can be bound to?

  • Thread starter Thread starter TallGuy789
  • Start date Start date
T

TallGuy789

Hi,

I'm trying to *programmatically* add a property to a Table Adapter class
that I can then bind to with a DetailsView control (via an Object Data
Source). I do not want to add another field in the SQL.

I have a database table TravelRequest that contains, amongst other things,
the fields SignOffName and SignOffDate. I have a table adapter
TravelRequestTable based on this table. I have a DetailsView control which
uses this via an Object Data Source. So far, should be all fairly standard
stuff.

What I want to do is add a property called SignOffNameDate to the table
adapter that combines the two fields and be able to bind to it in the
DetailsView control. I want to do it *programmatically* rather than adding
another column in the SQL because dealing with null values is tricky and
depends on some other business rules.

This is what I tried:

public partial class TravelRequestDS
{
public partial class TravelRequestRow
{
public string SignOffNameDate
{
get { return CombineNameDate(SignOffName, SignOffDate); }
}
}
}

This property works fine when I access it programmatically, but when I try
bind to it in my aspx page:

<asp:DetailsView ID="DetailsView_TravelRequest" runat="server"
AutoGenerateRows="False"
DataKeyNames="TravelRequestID"
DataSourceID="ObjectDataSource_TravelRequest">
<Fields>
<asp:BoundField DataField="SignOffNameDate"
HeaderText="Sign Off" />
...

I get an System.Web.HttpException exception, "A field or property with the
name 'SignOffNameDate' was not found on the selected data source."

I also tried creating a dummy SQL field. This generates a SignOffNameDate
property that can be bound to, but you can't override the functionality of
the property because the table adapter class is partial, not inherited.

Any ideas how I can do this? Is there an attribute I need to add to the
property?

Thanks
 
Show the actual *programatic* addition, as that will give us a clue how you
are doing what you are trying to do.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box! |
*************************************************
 
Back
Top