Hey,
Is it possible to do a databinding to a function, not to a property.
Ex. Object : Invoices - Invoice
Each Invoice has a collection of payments (an invoice can be paied in pieces) - payment
An invoice has also a function : getTotalPaid it returns a double.
Now I have a datagrid (ASP) I want to bind to several propertys of Invoice but I also want to show the getTotalPaid amount and the date of the last paiement.
Is that possible or do I have to make another custom class with a property TotalPaid and a property LastePaimentDat e and bind that classe to my datagrid. I think it is a littelbit to much of classes.
tkx,
Nic 3 1970
Nic,
You can not data bind to a function. Like you said, creating a custom
class that exposes the values you want through properties would be the best
way to go.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Nic" <Ni*@discussion s.microsoft.com > wrote in message
news:8D******** *************** ***********@mic rosoft.com... Hey,
Is it possible to do a databinding to a function, not to a property.
Ex. Object : Invoices - Invoice Each Invoice has a collection of payments (an invoice can be paied in
pieces) - payment An invoice has also a function : getTotalPaid it returns a double.
Now I have a datagrid (ASP) I want to bind to several propertys of Invoice
but I also want to show the getTotalPaid amount and the date of the last
paiement. Is that possible or do I have to make another custom class with a property
TotalPaid and a property LastePaimentDat e and bind that classe to my
datagrid. I think it is a littelbit to much of classes. tkx, Nic
Hi Nic,
What is going to be the source of the grid ?
If it's a collection of Invoices then you can do that in one of several
ways:
1- Use a method of the Invoice class to return the amount paid then you can
do something like this in your grid:
<asp:datagrid id=recordgrid runat="server" ShowHeader="fal se"
autoGenerateCol umns="False" >
<columns>
<asp:templateco lumn ItemStyle-VerticalAlign=" Middle" ItemStyle-Width="120"
ItemStyle-HorizontalAlign ="left" >
<itemtemplate >
<span ><%# ((TSR)Container .DataItem).GetI DCode()%></span>
</itemtemplate>
</asp:templatecol umn>
I'm binding the grid agains a collection of type TSR, this class has a
method named GetIDCode() , you can do something similar just replace your
binding expression like this:
<span ><%# ((Invoice)Conta iner.DataItem). GetTotalPaid(). ToString("C")
%></span>
The other way of doing it IF you don't want to change the Invoice class is
declare a method in the code behind that receive an Invoice instance and
return a string with the total paid.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Nic" <Ni*@discussion s.microsoft.com > wrote in message
news:8D******** *************** ***********@mic rosoft.com... Hey,
Is it possible to do a databinding to a function, not to a property.
Ex. Object : Invoices - Invoice Each Invoice has a collection of payments (an invoice can be paied in
pieces) - payment An invoice has also a function : getTotalPaid it returns a double.
Now I have a datagrid (ASP) I want to bind to several propertys of Invoice
but I also want to show the getTotalPaid amount and the date of the last
paiement. Is that possible or do I have to make another custom class with a property
TotalPaid and a property LastePaimentDat e and bind that classe to my
datagrid. I think it is a littelbit to much of classes. tkx, Nic
Hi Nic,
"Nic" <Ni*@discussion s.microsoft.com > wrote in message
news:8D******** *************** ***********@mic rosoft.com... Hi, The source of the grid is Invoices (in reality Invoices is a collection
object in the object Contract). Invoices consists of objects Invoice.
So you are ok :)
I tried what you proposed but at runtime he gives me an error : CS0246: The type or namespace name 'Invoice' could not be found (are you
missing a using directive or an assembly reference?)
Easy you have to include a reference to your assemblie , probably Invoices
is declared in another assembly ( dll ? )
Put this in the page:
<% @Import Namespace="Your .Assembly.Name. Here" %>
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
I don't understand why, the whole line in the grid is displaying data of
the invoice object. I have also a second question (struggeling whit datagrids) : My Invoice object has properties, some of the properties are also an
object ex. Code. The object Code has 2 properties : Id and Description.
In the datagrid I want to show my Invoice data and also Code.Descriptio n. But following binding don't work <asp:BoundColum n DataField="Invo iceId" HeaderText="Id" ></asp:BoundColumn > <asp:BoundColum n DataField="Code .description"
HeaderText="Des cription"></asp:BoundColumn > How can I bind to a property of a childobject.
Thanks for the help. Nic "Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi Nic,
What is going to be the source of the grid ? If it's a collection of Invoices then you can do that in one of several ways:
1- Use a method of the Invoice class to return the amount paid then you
can do something like this in your grid: <asp:datagrid id=recordgrid runat="server" ShowHeader="fal se" autoGenerateCol umns="False" > <columns> <asp:templateco lumn ItemStyle-VerticalAlign=" Middle"
ItemStyle-Width="120" ItemStyle-HorizontalAlign ="left" > <itemtemplate > <span ><%# ((TSR)Container .DataItem).GetI DCode()%></span> </itemtemplate> </asp:templatecol umn>
I'm binding the grid agains a collection of type TSR, this class has a method named GetIDCode() , you can do something similar just replace
your binding expression like this: <span ><%#
((Invoice)Conta iner.DataItem). GetTotalPaid(). ToString("C") %></span>
The other way of doing it IF you don't want to change the Invoice class
is declare a method in the code behind that receive an Invoice instance and return a string with the total paid.
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Nic" <Ni*@discussion s.microsoft.com > wrote in message news:8D******** *************** ***********@mic rosoft.com... Hey,
Is it possible to do a databinding to a function, not to a property.
Ex. Object : Invoices - Invoice Each Invoice has a collection of payments (an invoice can be paied in pieces) - payment An invoice has also a function : getTotalPaid it returns a double.
Now I have a datagrid (ASP) I want to bind to several propertys of
Invoice but I also want to show the getTotalPaid amount and the date of the last paiement. Is that possible or do I have to make another custom class with a
property TotalPaid and a property LastePaimentDat e and bind that classe to my datagrid. I think it is a littelbit to much of classes. tkx, Nic
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dtblankenship |
last post by:
Hello everyone,
I know this question has been asked many times in the forums, and after
spending a few days reading, I am still confused as to the answer.
I have a ListBox (lstBox), SqlConnection (sqlConnection),
SqlDataAdapter (daLookupData), SqlDataAdapter (daData), DataSet
(dsLookupData), and DataSet (dsData), all created via the IDE during
design-time. Here is the design of my simple tables: (An example
since I can't post my...
|
by: Kevin Swanson |
last post by:
I'm writing what should be a very simple app against an Oracle database. The
app has a number of user controls, any one of which is loaded into a main
display page using the loadControl method, depending on which menu item a
user selects. Each of these controls follows the same basic pattern: Get a
dataset from the database and then display the results using basic
databinding.
Everything works fine except that I'll occaisionally get an...
|
by: John Bailey |
last post by:
When I first built a few web pages in ASP .Net 2.0, I thought it was great.
The formview and detailview contorls would automatically layout the controls
for you, the update methods were automatically generated, and the
objectdatasource let you design against a business object through the gui.
Now I am working on my first real web application on 2.0, and I find this
automatic functionality doesn't do much beyond allowing me to generate...
|
by: Nathan Sokalski |
last post by:
I am using a SortedList as my DataSource. However, one of the things I am
using the data for is to generate the URL for the HyperLinks in my DataList.
Therefore, I need to use the result of a Server.UrlEncode() method with the
data as the parameter. The code I am using to get the data from the
SortedList (which successfully gives me the expected value) is:
<%# DataBinder.Eval(Container, "DataItem.Key") %>
However, when I try to modify...
|
by: GaryDean |
last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much
in answers so I'm reposting some questions posted by some of the programmers
here in our organization that never got answered...
In 1.1 we always did our own myDataAdapter.fills and we liked that control
for lots of good reasons. Now the new DataSource (or is it a
TableAdapter:Dataset) automatically fills the Gridview. How can we control
that fill?
In a...
| |
by: Zak Lomakus |
last post by:
Hi,
From my main page (default.aspx) I am calling another .aspx (e.g.
otherpage.aspx) page through Javascript using window.showModalDialog.
otherpage.aspx has a databoud control (webchart), bound to a SQLDataSource.
The first time otherpage.aspx is opened from default.aspx the databinding
occurs and the page_load occurs on otherpage.aspx. When the user closes that
modal form by clicking the close box ("X") at the top right corner of...
|
by: Dirk |
last post by:
Hello,
I have a problem to use databinding with my business layer classes. My
data class does not have simple properties (string, int or datetime),
instead, all my properties are objects of the generic type Field<T>
(see sample code).
public class Employee
{
public Field<stringForename
|
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= |
last post by:
Hello to all,
I want to know if DataBinding in asp.net 2,0 is better than to fill up the
values of the controls of the following form:
this.miControlTextBox.Text = valorParaControlTextbox;
Performance with databinding is good in asp.net 2.0 ? Would you prefer:
databinding or set value to Text property of control ?
|
by: Nathan Sokalski |
last post by:
I have a Repeater that uses a DataSource that has multiple fields. When the
values of these fields is displayed in the Repeater, there are fields that
are used in combination with other fields as well as by themselves. For
example, there may be a firstname field that is used in combination with a
lastname field as well as by itself. Using it by itself is simple, I have
done that many times. However, is there a way to use multiple fields in...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |