GridView edit mode issue


D

David C

I have a GridView bound to a DataSource. The GridView only has 1 column that
can be edited. If I click on the Edit LinkButton on a row with data in the
editable column then the RowDatabound event works fine. If that editable
column is NULL then it doesn't fire. This seems really strange. Can anyone
see what might be wrong? The RowDatabound event code is below. After that
is the markup for the GridView column template. Thanks in advance.

-David


Protected Sub gvPartsOnOrder_RowDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
gvPartsOnOrder.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowState = DataControlRowState.Edit Then
'row is in edit mode
Dim tb As TextBox = Page.Master.FindControl("txtMsg")
tb.Text = "I am in edit mode"
If IsDBNull(DataBinder.Eval(e.Row.DataItem,
"PartEstimatedDeliveryDate")) Then
'DateTime is empty so enable the mask
Dim obj As Object =
e.Row.FindControl("MaskedEditExtender1")
obj.Enabled = True
End If
End If
If e.Row.RowState = DataControlRowState.Normal _
Or e.Row.RowState = DataControlRowState.Alternate Then
If IsDBNull(DataBinder.Eval(e.Row.DataItem,
"PartEstimatedDeliveryDate")) Then
e.Row.Cells(4).BackColor = Drawing.Color.Red
Else
Dim dtEstDelivery As DateTime = _
Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem,
"PartEstimatedDeliveryDate"))
If dtEstDelivery < System.DateTime.Today Then
e.Row.Cells(4).BackColor = Drawing.Color.Red
End If
End If
End If
End If

End Sub


<asp:TemplateField HeaderText="Estimated<br />Delivery<br
/>Date/Time" SortExpression="PartEstimatedDeliveryDate">
<EditItemTemplate>
<asp:TextBox ID="txtPartEstimatedDeliveryDate"
runat="server" Text='<%# Bind("PartEstimatedDeliveryDate")
%>'></asp:TextBox>
<cc1:MaskedEditExtender ID="MaskedEditExtender1"
runat="server" AcceptAMPM="True"
TargetControlID="txtPartEstimatedDeliveryDate"
MaskType="DateTime" Mask="99/99/9999 99:99"
AutoComplete="False"
UserDateFormat="MonthDayYear" Enabled="False">
</cc1:MaskedEditExtender>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("PartEstimatedDeliveryDate","{0:M/d/yyyy hh:mm tt}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
 
Ad

Advertisements

D

David C

One other thing I noticed is that the code works on every other row. Hope
this helps.

David
 
Ad

Advertisements

D

David C

I figured it out. RowState is a total of the values in normal and alternate
rows so I had to add them together.

David
 

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

Top