Question Problem with code behind GridView.RowDataBound

Cuddles

New member
Joined
Oct 19, 2011
Messages
3
Programming Experience
1-3
Hi all,

I'm attempting to control users ability to enter data on a webpage. In this instance I only want them to be able to edit the data that is there, so if the property has no value, then the control will be disabled. I seem to have run into a problem. The code below only seems to work on each odd row of the GridView. So the first row they cannot edit the empty controls, second row they can, third row they cannot, etc... Apologies if I have missed something obvious, but I'm the only programmer where I work and a second pair of eyes is really handy every now and then.

VB.NET:
If e.Row.RowType = DataControlRowType.DataRow Then

            Dim personnelUnit As PersonnelUnit = CType(e.Row.DataItem, PersonnelUnit)

            Select Case e.Row.RowState

                Case DataControlRowState.Edit

                    If personnelUnit.EndDateAsDate.IsEmpty Then

EndDateAsDate is a property which gets is value from a SQL database. I have checked the data in the SQL database and it is Null for each row, yet the code only works on odd rows. Any help is appreciated.

Cheers,

Cuddles
 
I'm an amateur BTW, but you might try putting a value in the cells for what are supposed to be null values (for example, "N/A") instead of it being completely empty so you don't have to deal with the "IsEmpty" stuff. Just my two cents, good luck.
 
Thanks for the reply Joe, but the field in question is a date field, so it will only accept valid date values. It is just the fact it works on every odd row that has me stumped :(.
 
I've finally managed to fix this and what a pain it was.

The issue was the select case, I ended up replacing it with the following code:

VB.NET:
If ((e.Row.RowState And DataControlRowState.Edit) = DataControlRowState.Edit) Then

Cheers,

Cuddles
 
Back
Top