I am trying to hide the Calendar control in a edit template in the GridView. I tried Findcontrol but I still get the following error message:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 20: foreach (GridViewRow gridViewRow in GridView2.Rows)
Line 21: {
Line 22: ((Calendar)gridViewRow.FindControl("Calendar1")).Visible = true;
Line 23: }
Line 24: }
According to your code, it seems that you’d like to find and show Calendar control from GridViewRow that is edited, if that is the case, you could try to use the following code.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
28 Points
147 Posts
Need help: Findcontrol Calendar in Edit Template in GridView
May 19, 2016 10:41 AM|Matt99|LINK
Hi all,
I am trying to hide the Calendar control in a edit template in the GridView. I tried Findcontrol but I still get the following error message:
My code page:
My html page
I appreciate any help on this issue.
Thanks in advance.
All-Star
40535 Points
6233 Posts
Microsoft
Re: Need help: Findcontrol Calendar in Edit Template in GridView
May 20, 2016 02:15 AM|Fei Han - MSFT|LINK
Hi Matt99,
According to your code, it seems that you’d like to find and show Calendar control from GridViewRow that is edited, if that is the case, you could try to use the following code.
Best Regards,
Fei Han
Member
28 Points
147 Posts
Re: Need help: Findcontrol Calendar in Edit Template in GridView
May 21, 2016 10:26 AM|Matt99|LINK
Thank you,