e.Item.FindControl and NullException
-
I've having trouble retrieving reference to a LinkButton in my DataGrid: option 1 option 2 option 3 Now, from code-behind, I am trying to reference the controls, then toggle "Enable" and "Visible" properties to ON/OFF depending on various conditions. I do that using FindControl(..), and the exception I got was NullException (ie. It can't find the control I specified.) I checked the "ID" of the controls, they're correct. Here's the code: public void Command(Object sender, DataGridCommandEventArgs e) { switch(e.CommandName) { case "ConfigureSecurity": ((LinkButton)e.Item.FindControl ("btnConfigSecurity")).Enabled=false; //NULL EXCEPTION HERE!! Just this ONE control (The one from which the "command" was raised originally!!) Perhaps there's more than ONE server control in the same . ((DropDownList) e.Item.FindControl("drpConfigAccessRights")).Enabled=true; //OKAY, FindControl succeeded in retrieving reference to this control. I can retrieve reference to "btnDownload" though - it's the first server control in ItemTemplate. ((LinkButton) e.Item.FindControl("btnSubmitSecurityConfig")).Enabled=true; //OKAY, FindControl succeeded in retrieving referen