Main Page | Report this Page
.NET DotNet Forum Index  »  ASP.NET Forum  »  GridView edit mode issue...
Page 1 of 1    

GridView edit mode issue...

Author Message
David C...
Posted: Thu Nov 05, 2009 12:21 pm
Guest
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>
 
David C...
Posted: Thu Nov 05, 2009 12:43 pm
Guest
One other thing I noticed is that the code works on every other row. Hope
this helps.

David

"David C" <dlchase at (no spam) lifetimeinc.com> wrote in message
news:OLS3cyjXKHA.3504 at (no spam) TK2MSFTNGP05.phx.gbl...
Quote:
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

 
David C...
Posted: Thu Nov 05, 2009 1:20 pm
Guest
I figured it out. RowState is a total of the values in normal and alternate
rows so I had to add them together.

David

"David C" <dlchase at (no spam) lifetimeinc.com> wrote in message
news:OLS3cyjXKHA.3504 at (no spam) TK2MSFTNGP05.phx.gbl...
Quote:
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

 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Sat Nov 28, 2009 3:17 am