Solved

Databinding : find out what field a property is bound to

Posted on 2009-05-11
4
275 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

13 Experts available now in Live!

Get 1:1 Help Now