473,414 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

databinding to a property of a class ?

Help please

I have an example class called Person with 2 public properties Firstname
and Lastname, I cant create a textbox on an asp.net form bound to the
Person.Firstname property

Can anyone help with the required syntax?

if i do TExtbox1.text = x.firstname it works ok, but I want to edit the
textbox setting the value of x.firstname.

I am after a webcontrol that will edit person class with a button that will
save person class back to the database.

Here is the page code so far :

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim x As New person

x.firstname = "fred"

Page.DataBind()

'Textbox2 has a databinding on the text property = Person.firstname

End Sub

End Class

Public Class person

Private _firstname

Public Property firstname() As String

Get

Return _firstname

End Get

Set(ByVal Value As String)

_firstname = Value

End Set

End Property

End Class


Nov 18 '05 #1
2 1705
Bharat,
I'm assuming from your explanation that the person instance is out of scope
when page load is complete.

When it becomes a web user control embedded on a page where should oPerson
be declared so that its properties can be set from the control but
accessible from the containing page. I am thinking I want to save oPerson
into session State so that its properties can become available to other
pages in the browser session?

thanks for the clear explanation so far
Colin
"Bharat Biyani" <Bh**********@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
Hi Colin,

Follow these steps:
1) Declare a instance of the Person object in your class. YOu are currently doing it in the method. the instance should be a class member.

2)In aspx file make changes as shown below:
<asp:TextBox id="TextBox1" runat="server" Text=<%#p.FName%>/>
Here p is the instance name of the Person class declared in the code behind file.

3) In the PageLoad event binf the textbox to the object y calling the
TextBox1.DataBind() method.

This will bind the textbox to the object.

---
Bharat Biyani (bs*@orcim.com)
http://www.orcim.com
"Colin Robinson" wrote:
Help please

I have an example class called Person with 2 public properties Firstname and Lastname, I cant create a textbox on an asp.net form bound to the
Person.Firstname property

Can anyone help with the required syntax?

if i do TExtbox1.text = x.firstname it works ok, but I want to edit the
textbox setting the value of x.firstname.

I am after a webcontrol that will edit person class with a button that will save person class back to the database.

Here is the page code so far :

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub

Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim x As New person

x.firstname = "fred"

Page.DataBind()

'Textbox2 has a databinding on the text property = Person.firstname

End Sub

End Class

Public Class person

Private _firstname

Public Property firstname() As String

Get

Return _firstname

End Get

Set(ByVal Value As String)

_firstname = Value

End Set

End Property

End Class


Nov 18 '05 #2
Hi,

You can save the Person object in the session. However while creating an
instance of that object it should be done at class level so that it is
available for databinding.
You could do something like this:

Person oPer=(Person)Session[objPerson]; //declare as a class variable.
....
Do databinding
....
//Save changes to person as per the values in the textbox.
Save the person object back to the session.
Session[objPerson]=oPer;

---
Bharat Biyani (bs*@orcim.com)
http://www.orcim.com
"Colin Robinson" wrote:
Bharat,
I'm assuming from your explanation that the person instance is out of scope
when page load is complete.

When it becomes a web user control embedded on a page where should oPerson
be declared so that its properties can be set from the control but
accessible from the containing page. I am thinking I want to save oPerson
into session State so that its properties can become available to other
pages in the browser session?

thanks for the clear explanation so far
Colin
"Bharat Biyani" <Bh**********@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
Hi Colin,

Follow these steps:
1) Declare a instance of the Person object in your class. YOu are

currently
doing it in the method. the instance should be a class member.

2)In aspx file make changes as shown below:
<asp:TextBox id="TextBox1" runat="server" Text=<%#p.FName%>/>
Here p is the instance name of the Person class declared in the code

behind
file.

3) In the PageLoad event binf the textbox to the object y calling the
TextBox1.DataBind() method.

This will bind the textbox to the object.

---
Bharat Biyani (bs*@orcim.com)
http://www.orcim.com
"Colin Robinson" wrote:
Help please

I have an example class called Person with 2 public properties Firstname and Lastname, I cant create a textbox on an asp.net form bound to the
Person.Firstname property

Can anyone help with the required syntax?

if i do TExtbox1.text = x.firstname it works ok, but I want to edit the
textbox setting the value of x.firstname.

I am after a webcontrol that will edit person class with a button that will save person class back to the database.

Here is the page code so far :

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub

Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim x As New person

x.firstname = "fred"

Page.DataBind()

'Textbox2 has a databinding on the text property = Person.firstname

End Sub

End Class

Public Class person

Private _firstname

Public Property firstname() As String

Get

Return _firstname

End Get

Set(ByVal Value As String)

_firstname = Value

End Set

End Property

End Class



Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DraguVaso | last post by:
Hi, I'm having the following situation: - A class clsFournisseur with public property's which raise a MyPropertyChanged-event in the Set-method for each Property. Public Event NomChanged As...
1
by: Gary Shell | last post by:
I have a pair of combo boxes on a form. Both have their SelectedValue property bound to a column on a table called "Input_Output". One column is called "Class" and the second is called "SubClass"....
8
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...
5
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I...
0
by: optictygre | last post by:
Databinding with reflection I have a class, SmartString: Public Class SmartString ...Psuedo code follows Public Property Value() as String Return Me.Text
8
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...
2
by: Brian Pelton | last post by:
I am trying to bind a textbox to the property of a property. This code works when nested property is not null, but it fails when nested is null. (It fails when SiteLine.Site is null.) The...
2
by: Dustin Davis | last post by:
I've been having problems with databinding. I've created a simple solution to emulate the problem I can't figure out. Basically, I have a TextBox bound to a property in an object. When the property...
0
by: cmrchs | last post by:
Hi, I'm trying out Databinding to a Data Acces Layer using a GridView and ObjectDataSource-control The Update works fine but the Delete-method doesn't ??? <asp:GridView ID="GridView1"...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
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...
0
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.