Finding control in GridView

D

David C

I am trying to toggle a calendar control in a GridView and I am getting the
error "Object reference not set to an instance of an object."
The error is occurring in the 1st FindControl of the code below. I am using
an ImageButton next to a textbox so that when clicked, the calendar will
show.
I have to use FindControl because there are 3 controls in this 1 cell.
Thanks.


Protected Sub IBtnCalTask_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs)

Dim row As GridViewRow = gvFileTasks.SelectedRow

Dim varCalendar

varCalendar = row.FindControl("calDueDate")

If varCalendar.CssClass = "Hide" Then

Dim varTaskDate

varTaskDate = row.FindControl("txtTaskDate")

If varTaskDate.Text = "" Then

varCalendar.SelectedDate = DateTime.Today.ToShortDateString

Else

varCalendar.SelectedDate = varTaskDate.Text

End If

varCalendar.CssClass = "Show"

Else

varCalendar.CssClass = "Hide"

End If

End Sub

-David
 
D

David C

Nope. Same error. Does it have anything to do with order of events or
something as I am looking at the SelectedRow property?

David
Eliyahu Goldin said:
Do it for the cell rather than for the row:

varCalendar = row.Cells(0).FindControl("calDueDate")


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


David C said:
I am trying to toggle a calendar control in a GridView and I am getting
the error "Object reference not set to an instance of an object."
The error is occurring in the 1st FindControl of the code below. I am
using an ImageButton next to a textbox so that when clicked, the calendar
will show.
I have to use FindControl because there are 3 controls in this 1 cell.
Thanks.


Protected Sub IBtnCalTask_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs)

Dim row As GridViewRow = gvFileTasks.SelectedRow

Dim varCalendar

varCalendar = row.FindControl("calDueDate")

If varCalendar.CssClass = "Hide" Then

Dim varTaskDate

varTaskDate = row.FindControl("txtTaskDate")

If varTaskDate.Text = "" Then

varCalendar.SelectedDate = DateTime.Today.ToShortDateString

Else

varCalendar.SelectedDate = varTaskDate.Text

End If

varCalendar.CssClass = "Show"

Else

varCalendar.CssClass = "Hide"

End If

End Sub

-David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top