Solved

Databinding : find out what field a property is bound to

Posted on 2009-05-11
4
277 Views
Last Modified: 2012-05-06
Hi

I have a usercontrol with a property of Text, i am using this within a formview and binding using standard stuff

ie : Text='<%# Bind("ColumnName")%>'

now from within my usercontrol i need to know what the Text property is bound to, i dont want to have to have another property of FieldName and have to set it twice..

Thanks
0
Comment
Question by:crazyman
  • 2
  • 2
4 Comments
 
LVL 13

Author Comment

by:crazyman
ID: 24352856
Ive tried using

IDataBindingsAccessor acc = this as IDataBindingsAccessor;

but its always empty...
0
 
LVL 3

Expert Comment

by:OblivionSY
ID: 24355439
I'm trying to follow what you're trying to achieve. Controls should be encapsulated and as such, why would it need to know what property it was bound to on the outside form? Not sure how to achieve what you're asking. but maybe with what you're trying to achieve can come up with a solution?
0
 
LVL 13

Author Comment

by:crazyman
ID: 24358039
Yes encapsulation is great, this however is a means to an end and the time saved and flexibility it will bring will be worth it.

I have a user control that will display a textbox wit some autocomplete beaviour etc.. (Telerik RadControls to be precise).
Now this sits inside a formview that is bound to a business object, these object are created from Telerik OpenAccess ORM and as such contain metadata about the object fields, in this case Length...

As an excersise i am trying to evaluate the possiblility of the UI auto detecting the length of varchar/string fields via the orm business objects metadata, this works great if i know the name of the field if you set it via a property but its duplication and as such i would like to either set it via only a property or via the databinding expression...

At current i have

<DIS:TextField id="Field1" runat="server" DataField="UserName" Text='<%#Bind("UserName")%>' />

If i could get away with just the property and still allow 2 way binding then great theres your encapsulation...
0
 
LVL 3

Accepted Solution

by:
OblivionSY earned 500 total points
ID: 24359821
I think I see what you are trying to do. You could bind another property? so MaxLength=...

Otherwise, in code on te databound event, you could pass in the object and handle the displaying of text there, plus then you could get the length information?

Not sure how/if possible to get back to the other data. Sorry, not hugely helpful
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now