LinkButton in DataList

I have a datalist and in his header template I have linkbutton.In my codebehind file, which I wrote, as I always wrote:

((LinkButton)(DataList1.FindControl("LinkButton1"))).Enabled = false;

but this gives me an error:

The reference to the object is not installed in the instance of the object.

How can I access this link?

+3
source share
4 answers

You should use FindControl()in your template (e.g. ItemTemplate)

+2
source

Your call FindControldoes not find anything - you need to make sure that something is found before you pronounce it and try to use it.

This approach is safer:

LinkButton linkButton 
    = DataList1.FindControl("LinkButton1") as LinkButton;

if (linkButton != null)
    linkButton.Enabled = false;
+1
source

If LinkButton is embedded in a container, such as a panel or other control, you will need to get inside it. FindControl does not regress through child collection controls.

For example, you may need to do something similar using any nested control structure:

FindControl("Panel1").FindControl("LinkButton1").Enabled ...
+1
source

Try:

**LinkButton lnk = (LinkButton)e.Item.FindControl("LnkPager");**

Comment :: LnkPager is a link in My Datalist

0
source

Source: https://habr.com/ru/post/1736372/


All Articles