473,385 Members | 1,449 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,385 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 3996

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 date into a textbox(txtBeginDate And txtEndDate)...
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" src="popcalendar.js"></script> I call this calendar popup with a image...
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 user navigates to a particular month and picks a...
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. The datagrid control has selection buttons added...
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? Thanks Mike
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 calendar control popup which works fine when first...
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 ..there is a close button ..when i press close button...
1
by: KRISHNA PRAVI | last post by:
the error is "runtime error object expected" here is the code....................................................................................... <script language="javascript"...
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 but when i tried in Mozilla firefox it didnt...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.