472,331 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Use Javascript Calendar in DataGrid

I'm attempting to implement a javascript popup calendar in a DataGrid.
The calendar will be used to insert a date into a textbox. I keep
getting a "System.NullReferenceException: Object reference not set to
an instance of an object" error, which points to the following line:

lnkCalendar.Attributes("OnClick") =
String.Format("window.open('Calendar.aspx?textbox= {0}','cal','...')",
txtEstimatedDeploy)

Here is the complete code for the aspx page and its codebehind page:

aspx page:
<%@ Page Language="vb"
Src="BURSInsertSuccessful.aspx.vb"
Inherits="PSDataGrid" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<html>
<head>
<title>BURS - Insert Successful</title>
<style>
H3 {
font: 8pt arial;
font-weight: 600;
text-align: center;
}
H1 {
font: 8pt arial;
font-weight: 400;
text-align: center;
}
A {
font: 8pt arial;
font-weight: 400;
}
</style>
</head>
<body>
<h3>Corporate Information Services<br>Insert
Successful</h3>
<h1>A new project record has been created.<br>Click
"<b><u>Edit</u></b>" in the last
column to make changes to the report.</h1>
<table>
<form id="Form1" method="post"
runat="server">
<asp:datagrid id="dgProjectSummary"
runat="server"
ShowHeader="True"
ShowFooter="False"
BorderColor="black"
AutoGenerateColumns="False"
OnEditCommand="EditRecord"
OnUpdateCommand="UpdateRecord"
OnCancelCommand="CancelEdit">

<headerstyle BackColor="lightgray"
Font-Name="arial"
Font-Size="8"
Font-Bold="true"
ForeColor="black"
HorizontalAlign="center"
/>

<itemstyle
Font-Name="arial"
Font-Size="8"
HorizontalAlign="left"
VerticalAlign="top"
/>

<columns>

<asp:templatecolumn>
<itemtemplate>
<b>Project ID:</b>
<asp:label text='<%#
Container.DataItem("ProjectID")%>'
font-name="arial"
font-size="8" runat="server"
ID="Label1" NAME="Label1"/>
</itemtemplate>
<edititemtemplate>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Project</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("ProjectName")%>'
font-name="arial"
font-size="8" width="70"
runat="server" ID="Label2"
NAME="Label2"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtProjectName"
text='<%#
Container.DataItem("ProjectName")%>'
font-name="arial"
font-size="8" rows="10"
width="70" textmode="multiline"
wrap="true"
style="overflow:hidden"
runat="server">
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Project Description</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("ProjectDescription")%>'
font-name="arial"
font-size="8" width="100"
runat="server" ID="Label3"
NAME="Label3"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtProjectDescription"
text='<%#
Container.DataItem("ProjectDescription")%>'
font-name="arial" font-size="8"
rows="10" width="100"
textmode="multiline" wrap="true"
runat="server">
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Phase</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("Phase")%>'
font-name="arial"
font-size="8" width="39"
runat="server" ID="Label4"
NAME="Label4"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtPhase" text='<%#
Container.DataItem("Phase")%>'
font-name="arial"
font-size="8" rows="10"
width="39" textmode="multiline"
wrap="true"
style="overflow:hidden"
runat="server">
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Estimated Deploy</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("EstimatedDeploy").ToShortDateS tring
%>' font-name="arial"
font-size="8" width="65"
runat="server" ID="Label5"
NAME="Label5"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtEstimatedDeploy"
text='<%#
Container.DataItem("EstimatedDeploy").ToShortDateS tring
%>'
font-name="arial" font-size="8"
rows="1" width="65" runat="server">
</asp:textbox>
<asp:hyperlink id="lnkCalendar"
runat="server" navigateurl="Calendar.aspx"
target="_blank">Calendar</asp:hyperlink>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Recent Accomplishments</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("RecentAccomplishments")%>'
font-name="arial"
font-size="8" width="100"
runat="server" ID="Label6"
NAME="Label6"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox
id="txtRecentAccomplishments" text='<%#
Container.DataItem("RecentAccomplishments")%>'
font-name="arial" font-size="8"
rows="10" width="100"
textmode="multiline" wrap="true"
runat="server">
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Focus Items</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("FocusItems")%>'
font-name="arial"
font-size="8" width="100"
runat="server" ID="Label7"
NAME="Label7"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtFocusItems"
text='<%# Container.DataItem("FocusItems")%>'
font-name="arial"
font-size="8" rows="10"
width="100" textmode="multiline"
wrap="true" runat="server">
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Est. Benefits</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("EstBenefits")%>'
font-name="arial"
font-size="8" width="51"
runat="server" ID="Label8"
NAME="Label8"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtEstBenefits"
text='<%#
Container.DataItem("EstBenefits")%>'
font-name="arial"
font-size="8" rows="10"
width="51" textmode="multiline"
wrap="true" style="overflow:hidden"
runat="server">
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>IS Cost</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("ISCost")%>'
font-name="arial"
font-size="8" width="51"
runat="server" ID="Label9"
NAME="Label9"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtISCost" text='<%#
Container.DataItem("ISCost")%>'
font-name="arial"
font-size="8" rows="10"
width="51" textmode="multiline"
wrap="true" style="overflow:hidden"
runat="server">
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Corporate<br>IS Lead</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("CorporateISLead")%>'
font-name="arial"
font-size="8" width="70"
runat="server" ID="Label10"
NAME="Label10"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtCorporateISLead"
text='<%#
Container.DataItem("CorporateISLead")%>'
font-name="arial" font-size="8"
rows="10" width="70"
textmode="multiline" wrap="true"
style="overflow:hidden"
runat="server">
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Business Lead</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("BusinessLead")%>'
font-name="arial"
font-size="8" width="70"
runat="server" ID="Label11"
NAME="Label11"/>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtBusinessLead"
text='<%#
Container.DataItem("BusinessLead")%>'
font-name="arial" font-size="8"
rows="10" width="70"
textmode="multiline" wrap="true"
style="overflow:hidden"
runat="server">
</asp:textbox>
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Department</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("Department")%>'
font-name="arial"
font-size="8" width="100"
runat="server" ID="Label12"
NAME="Label12"/>
</itemtemplate>
<edititemtemplate>
<asp:listbox id="lbxDepartment"
font-name="arial" font-size="8"
width="100" rows="1"
DataTextField="DepartmentName"
DataValueField="DepartmentName" DataSource="<%#
GetDepartmentNames() %>"
runat="server" />
</edititemtemplate>
</asp:templatecolumn>

<asp:templatecolumn>
<headertemplate>
<b>Status</b>
</headertemplate>
<itemtemplate>
<asp:label text='<%#
Container.DataItem("Status")%>'
font-name="arial"
font-size="8" width="58"
runat="server" ID="Label13"
NAME="Label13"/>
</itemtemplate>
<edititemtemplate>
<asp:listbox id="lbxStatus"
font-name="arial" font-size="8"
width="58" rows="1"
DataTextField="Status"
DataValueField="Status" DataSource="<%#
GetStatus() %>"
runat="server" />
</edititemtemplate>
</asp:templatecolumn>

<asp:editcommandcolumn
ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel"
EditText="Edit" />
</columns>
</asp:datagrid>
<br>
<tr>
<td>
<asp:button id="btnReturn"
font-size="8" runat="server" text="Return to
Main Page" OnClick="btnReturn_Click"/>
</td>
</tr>
<tr>
<td>
<asp:Button id="btnInsert"
font-size="8" runat="server" text="Insert
Another Project" OnClick="btnInsert_Click"/>
</td>
</tr>
</form>
</table>
</body>
</html>
Codebehind page:

[code:1:0fdbcec583]
Imports System
Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI.WebControls

Public Class PSDataGrid

Inherits System.Web.UI.Page
Protected WithEvents dgProjectSummary As
System.Web.UI.WebControls.DataGrid

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
LoadGrid()
End If
End Sub

Private Sub LoadGrid()
Dim intProjectID As Integer
intProjectID = Session("ProjectID")

Dim dsProjectSummary As New DataSet()
Dim strConnection As String = "" 'Connection string
omitted from post
Dim objConnection As New SqlConnection(strConnection)
Dim objCommand As New
SqlCommand("dbo.ap_DisplayNewProject",
objConnection)

objCommand.CommandType = CommandType.StoredProcedure

Dim objParameter As New SqlParameter("@ProjectID",
SqlDbType.Int)
objCommand.Parameters.Add(objParameter)
objParameter.Direction = ParameterDirection.Input
objParameter.Value = intProjectID

objConnection.Open()
dgProjectSummary.DataSource = objCommand.ExecuteReader()
dgProjectSummary.DataBind()
objConnection.Close()
End Sub

Public Sub btnReturn_Click(ByVal Source As Object, ByVal E As
EventArgs)
Response.Redirect("default.htm")
End Sub

Public Sub btnInsert_Click(ByVal Source As Object, ByVal E As
EventArgs)
Response.Redirect("BURSProjectInsert.aspx")
End Sub

Public Sub EditRecord(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)
dgProjectSummary.EditItemIndex = E.Item.ItemIndex
LoadGrid()
End Sub

Public Sub CancelEdit(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)
dgProjectSummary.EditItemIndex = -1
LoadGrid()
End Sub

Public Sub UpdateRecord(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)
Dim strConnection As String = "" 'Connection string
omitted from post
Dim objConnection As New SqlConnection(strConnection)
Dim objCommand As New
SqlCommand("ap_UpdateProjectSummary",
objConnection)

Dim idProjectName As String =
CType(e.Item.FindControl("txtProjectName"),
TextBox).Text
Dim idProjectDescription As String =
CType(e.Item.FindControl("txtProjectDescription"),
TextBox).Text
Dim idPhase As String =
CType(e.Item.FindControl("txtPhase"),
TextBox).Text
Dim idEstimatedDeploy As String =
CType(e.Item.FindControl("txtEstimatedDeploy"),
TextBox).Text
Dim idRecentAccomplishments As String =
CType(e.Item.FindControl("txtRecentAccomplishments "),
TextBox).Text
Dim idFocusItems As String =
CType(e.Item.FindControl("txtFocusItems"),
TextBox).Text
Dim idEstBenefits As String =
CType(e.Item.FindControl("txtEstBenefits"),
TextBox).Text
Dim idISCost As String =
CType(e.Item.FindControl("txtISCost"),
TextBox).Text
Dim idCorporateISLead As String =
CType(e.Item.FindControl("txtCorporateISLead"),
TextBox).Text
Dim idBusinessLead As String =
CType(e.Item.FindControl("txtBusinessLead"),
TextBox).Text

objCommand.CommandType = CommandType.StoredProcedure

Dim objParameter1 As New
SqlParameter("@ProjectName", SqlDbType.VarChar,
100)
objCommand.Parameters.Add(objParameter1)
objParameter1.Direction = ParameterDirection.Input
objParameter1.Value = idProjectName

Dim objParameter2 As New
SqlParameter("@ProjectDescription", SqlDbType.VarChar,
2000)
objCommand.Parameters.Add(objParameter2)
objParameter2.Direction = ParameterDirection.Input
objParameter2.Value = idProjectDescription

Dim objParameter3 As New SqlParameter("@Phase",
SqlDbType.VarChar, 30)
objCommand.Parameters.Add(objParameter3)
objParameter3.Direction = ParameterDirection.Input
objParameter3.Value = idPhase

Dim objParameter4 As New
SqlParameter("@EstimatedDeploy",
SqlDbType.DateTime)
objCommand.Parameters.Add(objParameter4)
objParameter4.Direction = ParameterDirection.Input
objParameter4.Value = idEstimatedDeploy

Dim objParameter5 As New
SqlParameter("@RecentAccomplishments",
SqlDbType.VarChar, 2000)
objCommand.Parameters.Add(objParameter5)
objParameter5.Direction = ParameterDirection.Input
objParameter5.Value = idRecentAccomplishments

Dim objParameter6 As New SqlParameter("@FocusItems",
SqlDbType.VarChar, 2000)
objCommand.Parameters.Add(objParameter6)
objParameter6.Direction = ParameterDirection.Input
objParameter6.Value = idFocusItems

Dim objParameter7 As New
SqlParameter("@EstBenefits", SqlDbType.VarChar,
200)
objCommand.Parameters.Add(objParameter7)
objParameter7.Direction = ParameterDirection.Input
objParameter7.Value = idEstBenefits

Dim objParameter8 As New SqlParameter("@ISCost",
SqlDbType.VarChar, 15)
objCommand.Parameters.Add(objParameter8)
objParameter8.Direction = ParameterDirection.Input
objParameter8.Value = idISCost

Dim objParameter9 As New
SqlParameter("@CorporateISLead", SqlDbType.VarChar,
50)
objCommand.Parameters.Add(objParameter9)
objParameter9.Direction = ParameterDirection.Input
objParameter9.Value = idCorporateISLead

Dim objParameter10 As New
SqlParameter("@BusinessLead", SqlDbType.VarChar,
50)
objCommand.Parameters.Add(objParameter10)
objParameter10.Direction = ParameterDirection.Input
objParameter10.Value = idBusinessLead

objConnection.Open()
dgProjectSummary.DataSource = objCommand.ExecuteReader()
dgProjectSummary.DataBind()
objConnection.Close()

dgProjectSummary.EditItemIndex = -1
LoadGrid()
End Sub

Public Sub Item_Bound(Sender As Object, E As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgProjectSummary.ItemDataBound
Dim txtEstimatedDeploy As TextBox
txtEstimatedDeploy =
e.Item.FindControl("txtEstimatedDeploy")

Dim lnkCalendar As Hyperlink
lnkCalendar = e.Item.FindControl("lnkCalendar")

lnkCalendar.Attributes("OnClick") =
String.Format("window.open('Calendar.aspx?textbox= {0}','cal','...')",
txtEstimatedDeploy)
End Sub

Public Function GetDepartmentNames() As ICollection
Dim strConnection As String = "" 'Connection string
omitted from post
Dim objConnection As New SqlConnection(strConnection)
Dim daDeptNames As SqlDataAdapter = New
SqlDataAdapter("SELECT DepartmentName FROM Department",
objConnection)
Dim dsDeptNames As DataSet = New DataSet()

daDeptNames.Fill(dsDeptNames)
Return dsDeptNames.Tables(0).DefaultView
End Function

Public Function GetStatus() As ICollection
Dim strConnection As String = "" 'Connection string
omitted from post
Dim objConnection As New SqlConnection(strConnection)
Dim daStatus As SqlDataAdapter = New
SqlDataAdapter("SELECT Status FROM Status",
objConnection)
Dim dsStatus As DataSet = New DataSet()

daStatus.Fill(dsStatus)
Return dsStatus.Tables(0).DefaultView
End Function

End Class
[/code:1:0fdbcec583]

I'm rather new to programming in .NET so any suggestions will be
appreciated.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #1
0 3913

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

Similar topics

0
by: Marco Di Gregorio | last post by:
I'm having a problem I would like to display data to a datagrid I using a Calendar When i klik to a calendar i will put a begin date and an end...
1
by: Gilles T. | last post by:
I have calendar control in Javascript including in the Head of mu page: <script charset="iso-8859-1" language="JavaScript"...
1
by: Jay | last post by:
Hello, I have Calendar inside a datagrid. Whenever user clicks the edit button in the datagrid calendar is visible. The problem occurs when...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results....
4
by: Mike | last post by:
Hi, Is there a possibility to have one of the Web Control Datagrid's column as a Calendar when editing data? Any resources on this subject? ...
0
by: Caesar Augustus | last post by:
I'm having a problem with two different javascript controls in my app. The first chuck of javascript that I pasted into my app is the client-side...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender...
1
by: KRISHNA PRAVI | last post by:
the error is "runtime error object expected" here is the code..........................................................................................
1
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.