Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to bind key/value pair to an asp label

Tags:

c#

.net

asp.net

I have a situation which come in front of me very often but I don't have any solution to it right now. Suppose I have a key/value pair like this

UserID | UserName
-----------------
1      | Yogi
2      | Mike

I want to bind this data to an asp label control, Right now what I do is, I bind UserID to the tooltip of the label & UserName to the text of the label, It works fine but drawback is that when user hovers the label it shows UserID as a tooltip to the user which is obvious. I want to find some better way to do this job, please help me to get a better approach here.

like image 702
yogi Avatar asked Jun 07 '12 11:06

yogi


1 Answers

For ASP.Net

Create a custom attribute like

mylabel.Attributes["attributename"] = value;

For WinForms/WPF

Give it in its Tag property. I use that property for these kind of purposes.

Provide Username in Label and when it is label is hovered over, extract the tag (array or list) and display in tooltip.

mylabel.Tag = value;
like image 152
Nikhil Agrawal Avatar answered Nov 14 '22 21:11

Nikhil Agrawal