By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,978 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,978 IT Pros & Developers. It's quick & easy.

Detail view control problem

P: 32
Hello,

I have a simple vb.net 2005 application using an SQLserver database

There is a form , employees that has a grid view and a detail view control
The grid displays data and has a "Select" link as the leftmost column. Clicking on this displays employee details in the detail view.

The detail view further has Edit, Delete and New links, that help to maintain data.

My problem is this -

when the last employee record is deleted, the detail view must go to insert mode , so that the user can enter fresh data.

The defaultmode property of thd detail view is set to "Read only " at design time.

Right now, when the last record is deleted, the detail view disappears from the screen , as it is still in read-only mode

I have written the following code, it works in all cases, except when the last record on screen is deleted.

What am I missing ?

Expand|Select|Wrap|Line Numbers
  1.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  2.         Dim mycount As Integer = GridView1.Rows.Count
  3.         If mycount > 0 Then
  4.             DetailsView1.DefaultMode = DetailsViewMode.ReadOnly
  5.         Else
  6.             DetailsView1.DefaultMode = DetailsViewMode.Insert
  7.         End If
  8.         DetailsView1.Visible = True
  9.     End Sub
Any help highly appreciated
Nanda
Nov 25 '08 #1
Share this Question
Share on Google+
1 Reply


kenobewan
Expert 2.5K+
P: 4,871
If the row count is zero based, having one row leads to a 0 count. In that case not having any rows can lead to a count of -1. Either way write mycount to test.
Nov 27 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.