views:

92

answers:

2

hello,

can someone please explain to me how i can get the Text property of the linklabel that i have created at runtime?

I have tried:

string str = e.Link.LinkData;

...but that just displays an empty messagebox.

Thanks lots :)

+1  A: 

EDIT: Now that we know the type of e, try:

string str = e.Link.Description;

If the LinkLabel.Link doesn't have enough information, you'll have to refer to the LinkLabel itself. That may be the sender of the event (as suggested by MusiGenesis) but if it's not, I suggest you use a lambda expression or anonymous method to subscribe to the event - that way you can capture the LinkLabel and refer to the Text property directly.

Jon Skeet
private void llabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string str = e.Text; }Yes Mr Skeet, I have. But it comes up with a squiggly red line under 'Text' when I use the above code.
baeltazor
If you'd explained the type of `e` to start with, that would have helped. Editing...
Jon Skeet
@Jon: what, your ESP isn't working this morning? :)
MusiGenesis
I just tried this, and e.Link.Description returns a blank string.
MusiGenesis
It's possible that it was accepted due to the "capture" part of the answer. Hard to say.
Jon Skeet
+1  A: 

Since you have a mysterious "e" in your code, I assume you're trying to do this in the LinkLabel's LinkClicked event. To do this, you need to cast "sender" as a LinkLabel, like so:

private void linkLabel1_LinkClicked(object sender, 
    LinkLabelLinkClickedEventArgs e)
{
    LinkLabel lnklbl = (LinkLabel)sender;
    string str = lnklbl.Text;
}
MusiGenesis