Home All Groups Group Topic Archive Search About

LinkButton field and FindControl

Author
21 Apr 2006 4:50 PM
Roberto Kohler
Hi,

I have a  LinkButton in a TemplateField  inside my GridView
How do I access this control in the RowDataBound handler?

I've tried this:

Dim LinkEdit As LinkButton
If e.Row.RowType = DataControlRowType.DataRow Then
    LinkEdit  = e.Row.FindControl("LinkEdit")
    LinkEdit.CausesValidation="true"
End If

but it I get the error "Object reference not set to an instance of an
object"

Author
22 Apr 2006 6:20 AM
Teemu Keiski
Hi,

that should be somewhat right assuming LinkButton has ID "LinkEdit" and it's
not inside EditItemTemplate (except that if you have it declaratively there,
you might want to set CausesValidation already at that point, in aspx, to
avoid unnecessary state to be kept in ViewState,l when possible)

Can you show how you have declared the TemplateField?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Show quoteHide quote
"Roberto Kohler" <rkoh***@intranetslab.com> wrote in message
news:O2Nz9PWZGHA.3496@TK2MSFTNGP05.phx.gbl...
> Hi,
>
> I have a  LinkButton in a TemplateField  inside my GridView
> How do I access this control in the RowDataBound handler?
>
> I've tried this:
>
> Dim LinkEdit As LinkButton
> If e.Row.RowType = DataControlRowType.DataRow Then
>    LinkEdit  = e.Row.FindControl("LinkEdit")
>    LinkEdit.CausesValidation="true"
> End If
>
> but it I get the error "Object reference not set to an instance of an
> object"
>
>
>