Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 13th, 2007, 09:32 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default User Control in a GridView

I have a GridView where one of the columns shows a bound date value. When in edit mode, I want to work with a UserControl I created ("SmallCalendar"). The User Control is a simple date selector/display of 3 dropdowns. One each for Month, Day and Year.

When I try to access SmallCalendar, I get the error, "Object reference not set to an instance of an object".

The code I use is:
Code:
Public Sub GridView1_Edit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
        Dim i As Integer
        i = e.NewEditIndex
        Dim row As GridViewRow
        row = GridView1.Rows(i)
        Dim cal As New SmallCalendar

        cal = CType(row.Cells(6).FindControl("Calendar1"), SmallCalendar)
        TextBox1.Text = cal.SelectedDate_AsString
    End Sub
I placed SmallCalendar on the design surface for the Edit Template.

Thanks in advance for your comments.
 
Old August 13th, 2007, 09:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. are you sure that findcontrol is finding it??? maybe you are looking in the wrong cell...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 13th, 2007, 10:03 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sure that FindControl is not finding it, but I have tried the other cells (cells 0 through 7) to test it. My issue is that I know the control is supposed to be there. Is there some naming convention to use with FindControl that I am not aware of?
 
Old August 13th, 2007, 10:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

no convention.. just the name of the control.. did you try it in the row???

maybe the row is no more in edit mode and that's why you just can't find it??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 13th, 2007, 10:28 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Using FindControl on the row didn't work, but I think you're on to something with the Edit Mode.

It shows that it is is in normal mode for some reason.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable GridView delete button for a user rao965 ASP.NET 2.0 Professional 0 May 9th, 2008 12:30 PM
How to put a button control in a GridView control ryan.webb ASP.NET 2.0 Basics 2 December 28th, 2007 05:26 AM
Access User Control gridview gergi67 C# 2 November 9th, 2007 11:09 AM
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM
Help! Custom Server Control using User Control diehard ASP.NET 1.0 and 1.1 Professional 2 January 4th, 2006 12:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.