Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Can't Find control in Updatepanel, Gridview

$
0
0

Hello,

I have a Gridview within a Updatepanel with a button. I want to show the button when some value is true. This is my code in aspx

<asp:UpdatePanel ID="UpdatePanel1" ClientIDMode="Static" runat="server"><ContentTemplate><div id="dvMContent" class="dvMainContent" runat="server" ><asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="500" DynamicLayout="true"><ProgressTemplate><img src="../Images/ajax-loader.gif" alt="Wachten" height="25" width="25" /></ProgressTemplate></asp:UpdateProgress><asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CssClass="grvHeader" DataKeyNames="WetTekstID" 
                            GridLines="None"  CellPadding="0" DataSourceID="edsWetTekst" ShowHeader="False" ><Columns><asp:TemplateField ><ItemTemplate><h3><asp:Label ID="Label3" runat="server" Text='<%# Eval("Wet_Titel") %>'  style="float:left;"></asp:Label></h3><asp:Button ID="btnArchief" runat="server" CssClass="imbArchief"/></asp:TemplateField><%--<asp:BoundField DataField="Wet_Titel"  HtmlEncode="false" ApplyFormatInEditMode="true" SortExpression="Wet_Titel" />--%></Columns></asp:GridView></div></ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="trvWettekst" /></Triggers></asp:UpdatePanel>

This is my code behind

 private void ArchiefButtonVisible()
        {
            int trvValeu = Convert.ToInt32(trvWettekst.SelectedValue);
            int result = (from acm in this._context.tbl_WetTekstenArchief
                         where (acm.WetTekstID == trvValeu)
                         select acm.WetTekstID).FirstOrDefault();

            var btn = (Button)GridView2.TemplateControl.FindControl("btnArchief");
            //Button btn = (Button)GridView2.FindControl("btnArchief2");
            if (result > 0)
            {
                btn.Visible = false;
            }
            else
            {
                btn.Visible = true;
            }
        }

But i get the error: An exception of type 'System.NullReferenceException' occurred in Bouwgegevens.dll but was not handled in user code

Additional information: Object referencenotset to an instanceof an object.

someone has asolution.

regardsMark

 


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>