Solved

Databinding : find out what field a property is bound to

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Runtime Error 2 28
ASP.net Run 3 sliders vertically as opposed to horizontally 9 20
SQL Exceptions 3 39
Capture logon name 13 46
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

14 Experts available now in Live!

Get 1:1 Help Now