PC Review


Reply
Thread Tools Rate Thread

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

 
 
TallGuy789
Guest
Posts: n/a
 
      4th Feb 2009
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:

<aspetailsView 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
 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      5th Feb 2009
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! |
*************************************************

"TallGuy789" <(E-Mail Removed)> wrote in message
news:3CE439AA-DCB1-4513-AEDD-(E-Mail Removed)...
> 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:
>
> <aspetailsView 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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning Typed Dataset Table Adapter Connection Property A Web Config Connection At Runtime billy.murray@scomagg.com Microsoft ASP .NET 0 13th Dec 2006 11:29 AM
Adding rows to a bound table that is bound to DataGridView(DataSou =?Utf-8?B?S2V2aW4gQnVydG9u?= Microsoft Dot NET Framework Forms 2 22nd Jun 2006 06:05 AM
Bound Column property =?Utf-8?B?bmVlcmFq?= Microsoft Access Forms 1 26th Jul 2005 10:23 PM
Network adapter is not bound to TCP/IP in WinXP Alla Windows XP Setup 0 7th Dec 2003 04:43 AM
How to throw and catch an exception in the property set when property is bound to a wiform control Keith Roe Microsoft Dot NET Framework 2 4th Dec 2003 05:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:05 AM.