DetailsView Index out of Range?

  • Thread starter Timothy H. Schilbach
  • Start date
T

Timothy H. Schilbach

Hi Everyoine,

I am populating a DetailsView with a record from a user and everything
runs fine. What I want to do on the databinding is to go through each row
and make sure there is data beign displayed. Now I have setup the following
routine to do just that:

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
Dim row As DetailsViewRow
For Each row In DetailsView1.Rows
If String.IsNullOrEmpty(row.Cells(1).Text) Then
row.Visible = False
End If
Next
End SubWhen I run my code I get the dreaded: Specified argument was out
of the range of valid values.Parameter name: index When I change the cells
to: row.Cells(0) it runs fine. Now obviously there is a Cell(0) and Cell(1)
as you can see my results below. What is happening that I cannot access
Cells(1)? Any help is greatly appreciated.Cn uName DistinguishedName
CN=UserName,OU=Email,DC=nowhere,DC=local DisplayName Timothy Schilbach
GivenName User Sn Name Mail (e-mail address removed) alias1
(e-mail address removed) alias2 alias3 alias4 alias5
 
T

Timothy H. Schilbach

Hi Everyone,

Wow I feel like a bonehead. I have been coding for 2 days straight and got
hung up on something this easy. Well the whole isse is that come of my
Rows(i).Cells(1).Count were equal to 1! Oooopppsss, guess I forgot about the
last row that is the command button row. Wee here is the code I used to fix
it. I hope it helps someone else in the future.

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
Dim row As DetailsViewRow
For Each row In DetailsView1.Rows
If row.Cells.Count <> 1 Then
Response.Write(row.Cells.Count)
If String.IsNullOrEmpty(row.Cells(1).Text) Or
row.Cells(1).Text = "&nbsp;" Then
row.Visible = False
End If
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top