Question

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 :)

Was it helpful?

Solution

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.

OTHER TIPS

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top