Wrox Programmer Forums
|
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
 
Old January 30th, 2004, 11:40 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default 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


 
Old January 30th, 2004, 12:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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
 
Old January 30th, 2004, 12:05 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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



 
Old January 30th, 2004, 12:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can generate the Databindings dynamically, I have done it through code. The textbox has a databindings property.
 
Old January 30th, 2004, 01:07 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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.

 
Old January 30th, 2004, 02:02 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
 
Old January 30th, 2004, 03:04 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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







Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding to a Listbox rwebb616 Visual Basic 2005 Basics 1 June 1st, 2008 04:59 PM
Need help understanding databinding asp_convert ASP.NET 2.0 Basics 0 February 11th, 2007 07:17 PM
databinding for datagrid? drachx General .NET 5 October 28th, 2004 03:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.