 |
| ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 30th, 2004, 11:40 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Dynamic DataBinding
can you specify a data binding statement in your code behind.. something like this
tbDateDisenrolled.Text = "<%# DataBinder.Eval(dsEnrollmentDate, 'Tables[0].DefaultView.[0]." + strProgStatusDateField + "', '{0:d}') %>"
the string formats correctly, but it puts the string in the text box...
Is there a way to set the databinding column, type etc in the code behind? I thought this was possible.
thanks,
Jim
|
|

January 30th, 2004, 12:03 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
I think you have to specify data binding through the databindings property on the textbox, such as:
Code:
tbDateDisenrolled.DataBindings.Add("text", dsEnrollmentDate.Tables[0].DefaultView, strProgStatusDateField)
See: http://msdn.microsoft.com/library/de...saddtopic2.asp
|
|

January 30th, 2004, 12:05 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Yes you can do that if you have a physical dataset to work with, if yoiu create it through the GUI. However, I am creating all my objects in code, so i have to generate the binding expression dynamically.
Thanks
|
|

January 30th, 2004, 12:27 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
You can generate the Databindings dynamically, I have done it through code. The textbox has a databindings property.
|
|

January 30th, 2004, 01:07 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
thanks. Yes I saw that, the problem I am having is that the column I am binding to can change, it is not always the same one, so the string I create has a variable in it. But it cannot evaluate it when it tries to bind.
|
|

January 30th, 2004, 02:02 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
If all you want to do is populate the text of a textbox when you bind your dataset, just set the property value after you execute your dataset bind:
tbDateDisenrolled.Text = dsEnrollmentDate.Tables[0].DefaultView.[0].Item(strProgStatusDateField)
Use standard formatting practices to format it:
String.Format("{0:d}", dsEnrollmentDate.Tables[0].DefaultView.[0].Item(strProgStatusDateField))
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

January 30th, 2004, 03:04 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Peter,
Thanks, you always come through. I actually had to format my code like this for it to work"
[b]tbDateDisenrolled.Text = String.Format("{0:d}", dsEnrollmentDate.Tables(0).DefaultView(0).Item(str ProgStatusDateField))b]
This kilss 2 birds with one stone, the binding issue and the formatting issue.
Thanks again!!
Jim
|
|
 |