473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Finding control in GridView

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

Nov 14 '07 #1
1 1530
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" <dl*****@lifetimeinc.comwrote in message
news:u7**************@TK2MSFTNGP04.phx.gbl...
>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



Nov 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
0
by: John Smith | last post by:
ASP.Net 2.0 / C# / IIS 6 I have 2 pages. The master page consists of a tabbed menu created using the Menu and MultiView controls. Something like this: ...
0
by: John Smith | last post by:
If anyone can help, I would very muchly appreciate it. I have a main page that uses the .net 2.0 menu control with the multiview controls as the menu choices. This works fine. One of the menu...
0
by: MRW | last post by:
For some strange reason, I'm having problems finding a GridView in a FormView. I keep getting the error: Object reference not set to an instance of an object. I have the code below, it's very...
6
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
0
by: Sobin Thomas | last post by:
Hi All, How can I bind the Gridview control to Sql Datasource control on a button click(I see majority of the articles binding datasource at page load) I need to enable the paging and sorting of...
1
by: Sobin Thomas | last post by:
Hi All, How can I bind the Gridview control to Sql Datasource control on a button click(I see majority of the articles binding datasource at page load) I need to enable the paging and sorting of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.