对象引用未设置为模板控件上的对象实例

时间:2016-03-23 09:00:40

标签: c# asp.net linkbutton findcontrol templatefield

感谢有益的网站.. gridview的代码如下:

<asp:GridView ID="gridmem" runat="server" AutoGenerateColumns="False" CellPadding="3" GridLines="Vertical" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" DataKeyNames="UserName" style="z-index: 1; left: 88px; top: 32px; width: 255px; text-align: left; position: absolute; height: 217px" >
    <AlternatingRowStyle BackColor="#DCDCDC" />
    <Columns>
        <asp:BoundField DataField="UserName" HeaderText="User Name" />
        <asp:BoundField DataField="Email" HeaderText="Email" />
        <asp:CommandField ShowSelectButton="true" />
        <asp:TemplateField  HeaderText="Activing"><ItemTemplate>
        <asp:LinkButton  ID="Activating" runat="server" Text="Active" BackColor="Yellow" OnClick="Activating_Click" ClientIDMode="Static" />&nbsp;&nbsp; <asp:LinkButton ID="deActive"  Text="DeActive" BackColor="yellow" runat="server" Visible="false" OnClick="deActive_Click" /></ItemTemplate></asp:TemplateField>
    </Columns>
</asp:GridView>

// code .cs:

protected void Activating_Click(object sender, EventArgs e)
{
    gridmem.TemplateControl.FindControl("deActive").Visible = true;
}

但错误正在上线;

  

错误:对象引用未设置为对象的实例。

为什么会出现错误???

0 个答案:

没有答案