make a component in a repeater get enabled = false

0

I have a button inside a repeater. As it is in a repeater, it only appears in the DataBind () of the repeater. Using the variable and event, I get to this component like this:

protected void rptDocumentosRepeater_ItemDataBound(object source, RepeaterItemEventArgs e)
        {
            //Declarações
            try
            {
                //Instancias e Inicializações
                //Desenvolvimento
                if (....)
                {
                    e.Item.FindControl("fiuDocumentoUpload").
                }
            }
            catch
            { throw; }
        }

It turns out that I need to give an Enabled = false and I can not. In this command e.Item.FindControl("fiuDocumentoUpload"). I can not bring Enabled. I get the Visible, but the Enabled does not. How do I do it?

Declaring it in Asp.Net

<td class="ajusteTdIe">
    <asp:FileUpload ID="fiuDocumentoUpload" runat="server" CssClass="acessos" />
</td>
    
asked by anonymous 09.02.2015 / 18:09

2 answers

2

Have you tried casting for your kind of component?

var componente = (FileUpload)e.Item.FindControl("fiuDocumentoUpload");

if(componente != null)
    componente.Enabled = false;
    
09.02.2015 / 18:25
0

As the other friend said, you need to cast a cast. Home I tried to add as a comment in the answer but I still do not have enough score for this (I'm new here). Home I believe that his exception to the cast occurred the moment he went through another element of the list and tried to cast a cast. Use the cast with "as" that it will bring null if cast is not possible, like this:

var componente = e.Item.FindControl("fiuDocumentoUpload") as FileUpload;
if(componente != null)
    componente.Enabled = false;

Or, check the object type before, like this:

var componente = e.Item.FindControl("fiuDocumentoUpload");
if (componente is FileUpload)
    ((FileUpload)componente).Enabled = false;
    
02.05.2015 / 02:12