Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - GridView edit mode issue

 
Thread Tools Search this Thread
Old 11-05-2009, 05:21 PM   #1
Default GridView edit mode issue


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
  Reply With Quote
Old 11-05-2009, 05:43 PM   #2
David C
 
Posts: n/a
Default Re: GridView edit mode issue
One other thing I noticed is that the code works on every other row. Hope
this helps.

David

"David C" <> wrote in message
news:...
>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
  Reply With Quote
Old 11-05-2009, 06:20 PM   #3
David C
 
Posts: n/a
Default Re: GridView edit mode issue
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" <> wrote in message
news:...
>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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Possible motherboard issue sandy58 Computer Support 5 03-07-2009 11:22 PM
Re: Possible motherboard issue Centre Parting Computer Support 0 03-03-2009 12:49 PM
Major ActiveX Domain issue. NOT LOCAL PC ISSUE joe.valentine@gmail.com Computer Support 8 02-06-2006 09:03 PM
DHCP fails on wireless networks, Is KB313896 still an issue? =?Utf-8?B?Q2hyaXMgVGFuZ2Vy?= Wireless Networking 6 08-23-2004 03:55 PM
Win2K SP4 - what's the verdict? Max Quordlepleen Computer Support 6 09-16-2003 11:23 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46