Catch empty item template? (1 Viewer)

Sergeant

Someone's gotta do it
Local time
Today, 18:46
Joined
Jan 4, 2003
Messages
638
In my DetailsView, when there is no matching record, I want to switch it to Insert Mode.
I have tried
Code:
If Me.DetailsView1.Rows.Count = 0 Then
    Me.DetailsView1.DefaultMode = DetailsViewMode.Insert
Else
    Me.DetailsView1.DefaultMode = DetailsViewMode.ReadOnly
End If
but that doesn't work.

(Kodo, I'm sorry if I'm wearing you out here :( )
 

Kodo

"The Shoe"
Local time
Today, 18:46
Joined
Jan 20, 2004
Messages
707
I'll have to set up a test on this one myself. I'm not sure off the top of my head.
Are you using an object datasource? or.. how are you binding the data. If you could zip your aspx and vb files for that page, that would be helpful for me to help you.
 

Sergeant

Someone's gotta do it
Local time
Today, 18:46
Joined
Jan 4, 2003
Messages
638
The DetailsView is using a datasource on tblPositionFill (this will add a record to that bridging table to 'assign' a person to a position)...it is tied to the gridview selected record. The gridview pulls data from Pers table left join on PositionFIll table, so people not assigned don't have an associated record in the positionfill table.

I could put it in default mode "Insert", but no way to edit if there is a current record. With it in default mode "ReadOnly", if no record esists...the DetailsView doesn't appear.

If the person's already assigned, I want ReadOnly to show...if not assigned, I want Insert to show.


There is not a .vb file for the page...code is in page.
 

Attachments

  • index.zip
    2.1 KB · Views: 292

Kodo

"The Shoe"
Local time
Today, 18:46
Joined
Jan 20, 2004
Messages
707
I should be able to take a look at this tonight while I'm bored out of my skull in my database class.
 

Sergeant

Someone's gotta do it
Local time
Today, 18:46
Joined
Jan 4, 2003
Messages
638
Update: (My interim fix)
I set the default view to readonly.
On the empty item template, I added a label ("No assignment loaded")...
and a button ("Create new assignment") with code:
Me.DetailsView1.ChangeMode(DetailsViewMode.Insert)

That may actually be the best answer, since the original problem was that I wanted direct access to INSERT if no assignment was loaded...If an assignment IS loaded, you can click the built-in edit or new buttons.
 

Kodo

"The Shoe"
Local time
Today, 18:46
Joined
Jan 20, 2004
Messages
707
That acutally does sound like the more logical way to approach this. Sorry I didn't have a chance to look at your code.. tonights lab was actually quite interactive. Scripting an entire db structure with sprocs and triggers to-boot. Joy.. needless to say it took quite a while and I didn't get a chance to load up vs 2005 at all. :(
 
S

SteelerFan

Guest
DetailsView and Empty Data Source

In the DataBound event, you can check for the number of Pages. If less than 1, call ChangeMode to change to Insert.

Protected Sub MyDetails_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyDetails.DataBound
If MyDetails.PageCount < 1 Then MyDetails.ChangeMode(DetailsViewMode.Insert)
End Sub

HTH
 
S

SteelerFan

Guest
Note: There's a gotcha

In the databound event, PageCount will always be 0 if the control was in InsertMode when the control was bound.

Make sure to reset it to readonly when needed.
 

Sergeant

Someone's gotta do it
Local time
Today, 18:46
Joined
Jan 4, 2003
Messages
638
SteelerFan said:
In the DataBound event, you can check for the number of Pages. If less than 1, call ChangeMode to change to Insert.

Protected Sub MyDetails_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyDetails.DataBound
If MyDetails.PageCount < 1 Then MyDetails.ChangeMode(DetailsViewMode.Insert)
End Sub

HTH
Thanks for the insight there...seems like a good method.
I actually put this project on the back burner because my EMPLOYER has no plans to load the dotNET 2.0 framework.
 

Users who are viewing this thread

Top Bottom