Detail View Null Reference

InsertTemplate Null Reference Exception

Page 1 of 1

3 Replies - 1428 Views - Last Post: 21 July 2009 - 06:24 AM Rate Topic: -----

#1 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Detail View Null Reference

Post icon  Posted 20 July 2009 - 08:33 AM

I have a 2 GridView/DetailsView pairings.

The first pair displays (gridview) and allows editing (detailsview) of the projects a user is assigned. If the user is assigned Admin to the project then they can edit the project otherwise they can view the tasks (2nd pairing of GridView/DetailsView) assigned to them within the project.

The second pair of controls will either allow the user to edit 2 fields or edit the editable fields of a task. Basically, if a user is Admin to the project they can edit all editable fields within the Tasks Details View. But if they have merely been assigned a task within the project then they can only edit 2 fields (comments and status) of the task.

The problem:
As Admin to the project, if i select a project to view its list of tasks and their have been no tasks created (new project), then it brings up the Tasks Details View in Insert mode and i can start inserting data into the detailsview and insert into the database. If the project has tasks and i want to view the tasks details then it shows the details and the editable fields, as it should for both processes. The problem is if i look at a task for a project (in ReadOnly mode) and then want to view the tasks of a project that does not have any tasks yet, it throws a NullReferenceException error at the line posted below:

CType(dvwUserTask.FindControl("cboINSTaskPName"), DropDownList).SelectedValue = tmpPID


I have segregated the code some to help with the debugging but it hasnt changed the error.

					
If tblProjTasks.Count <= 0 Then
  If (gvwUserProjects.Rows(selIndex).Cells(3).Text = Session("userid").ToString) Or (gvwUserProjects.Rows(selIndex).Cells(4).Text = Session("userid").ToString) Then
	dvwUserTask.ChangeMode(DetailsViewMode.Insert)
	Dim tmpPID As Integer = CType(gvwUserProjects.Rows(selIndex).Cells(2).Text, Integer)
	CType(dvwUserTask.FindControl("cboINSTaskPName"), DropDownList).SelectedValue = tmpPID
	CType(dvwUserTask.FindControl("lblINSTaskTID"), Label).Text = 1
	dvwUserTask.Visible = True
  End If
Else
  gvwUserProjTasks.DataSource = tblProjTasks
  gvwUserProjTasks.DataBind()
  gvwUserProjTasks.Visible = True
End If



Design:
I have setup the Gridview(GV) as a readonly interface and the DetailsView(DV) as the main editing interface. The GV & DV are in HTML tables and i have 2 tables, one for Projects and one for Tasks. Both DV controls have a ReadOnly, Edit, and Insert Control Template structure. The problem is directly related to the Tasks DV and not the Projects DV. Seems it is having problems going from the RO mode to the INS mode.

Debugging:
I have verified that the name of the control in the INS mode is correct, which it is cause if i do the INS mode first it brings up the DV properly with no error. But it only shows up when i go from RO mode to INS mode. As you can see in the code segment above, i change the mode to INS before i make the reference to the control.

Update to problem
When i comment out the NullReferenceException line above it works correctly, when going from a Project View RO in the DV to another Project Insert in the DV.

If tblProjTasks.Count <= 0 Then
  If (gvwUserProjects.Rows(selIndex).Cells(3).Text = Session("userid").ToString) Or (gvwUserProjects.Rows(selIndex).Cells(4).Text = Session("userid").ToString) Then
	dvwUserTask.ChangeMode(DetailsViewMode.Insert)
	'Dim tmpPID As Integer = CType(gvwUserProjects.Rows(selIndex).Cells(2).Text, Integer)
	'CType(dvwUserTask.FindControl("cboINSTaskPName"), DropDownList).SelectedValue = tmpPID
	CType(dvwUserTask.FindControl("lblINSTaskTID"), Label).Text = 1

	dvwUserTask.Visible = True
  End If
Else


This post has been edited by woodjom: 20 July 2009 - 12:54 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Detail View Null Reference

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Detail View Null Reference

Posted 20 July 2009 - 04:47 PM

Can you post the source of the page?

I assume you are using a DropDownList in a TemplateField. Correct?
Was This Post Helpful? 0
  • +
  • -

#3 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: Detail View Null Reference

Posted 20 July 2009 - 06:07 PM

View PostJayman, on 20 Jul, 2009 - 05:47 PM, said:

Can you post the source of the page?

I assume you are using a DropDownList in a TemplateField. Correct?


that is correct....it works when i go straight to Insert....and if i go from Insert to Insert....but for some reason its not liking going from ReadOnly to Insert. I have my Edit and Readonly modes databound by Eval but my Insert mode has no binding...i pull the info from the editable fields and then push them through a query for the Insert query.

Let me get back to work and post the control source....as well as the event code that opens the detailsview.

Also, if i go from Edit->RO->Insert in the same control its fine....its just when i go from the Gridview_RowCommand to DetailsView_InsertMode is where the problem arises....i dont have a problem anywhere else except between these two controls

This post has been edited by woodjom: 20 July 2009 - 06:09 PM

Was This Post Helpful? 0
  • +
  • -

#4 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: Detail View Null Reference

Posted 21 July 2009 - 06:24 AM

ASP Forum Posting <---- is the answer.

Evidently i missed DataBind after ChangeMode but before control assignment. I was databinding all over the place for modechanges and such, i missed one and it was a quirky bug.

Thanx for the interest and assistance :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1