[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4350
  • Last Modified:

GridView RowUpdating Event Not Firing

Greetings;

I have read several of the previous help questions on when the gridView RowUpdating event doesn't fire. I am confused at this point on why my markup and code behind is not touching the RowUpdating event when Update button is clicked.

I also don't understand when I select the gridView control and look at the events in the Properties window of Visual Studio 2010 why I see all the proper event procedures listed for each event I expect to use. The Edit, Delete and Insert events work as I expect. Only the Update event does not seem to fire.

The markup and code behind are as follows:

            <asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="False"
                OnRowUpdating="gvProducts_RowUpdating"
                CellPadding="4" ForeColor="#333333" GridLines="None" 
                HorizontalAlign="Center">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:CommandField ButtonType="Button" ShowEditButton="True" 
                        ShowInsertButton="True" />
                    <asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
                    <asp:TemplateField HeaderText="Product Id">
                        <AlternatingItemTemplate>
                            <asp:Label ID="lblProductId" runat="server" Text='<%# Bind("strProductId") %>'></asp:Label>
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbxProductId" runat="server" 
                                Text='<%# Bind("strProductId") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblProductId" runat="server" Text='<%# Bind("strProductId") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle Wrap="False" />
                        <ItemStyle Wrap="False" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Product Name">
                        <AlternatingItemTemplate>
                            <asp:Label ID="lblProductName" runat="server" 
                                Text='<%# Bind("strProductName") %>'></asp:Label>
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbxProductName" runat="server" 
                                Text='<%# Bind("strProductName") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblProductName" runat="server" 
                                Text='<%# Bind("strProductName") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle Wrap="False" />
                        <ItemStyle Wrap="False" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Active?">
                        <AlternatingItemTemplate>
                            <asp:Label ID="lblActive" runat="server" Text='<%# Bind("blnActive") %>'></asp:Label>
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddlActive" runat="server">
                                <asp:ListItem Value="0">No</asp:ListItem>
                                <asp:ListItem Value="1">Yes</asp:ListItem>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblActive" runat="server" Text='<%# Bind("blnActive") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle Wrap="False" />
                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                    </asp:TemplateField>
                    <asp:BoundField DataField="dtCreated" HeaderText="Created" ReadOnly="True">
                    <HeaderStyle Wrap="False" />
                    <ItemStyle Wrap="False" />
                    </asp:BoundField>
                    <asp:BoundField DataField="dtUpdated" HeaderText="Updated" ReadOnly="True">
                    <HeaderStyle Wrap="False" />
                    <ItemStyle Wrap="False" />
                    </asp:BoundField>
                    <asp:BoundField DataField="tstValue" HeaderText="Timestamp" ReadOnly="True" 
                        Visible="False" />
                </Columns>
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                <SortedAscendingCellStyle BackColor="#FDF5AC" />
                <SortedAscendingHeaderStyle BackColor="#4D0000" />
                <SortedDescendingCellStyle BackColor="#FCF6C0" />
                <SortedDescendingHeaderStyle BackColor="#820000" />
            </asp:GridView>



Protected Sub gvProducts_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvProducts.RowUpdating

        Dim strProductIdOld As String = Session.Item("s_strProductIdOld")
        Dim drProduct As schRegUsers.up_s_ProductAllRow = dsRegUsers.up_s_ProductAll.FindBystrProductId(strProductIdOld)
        Dim tbxProductId As New TextBox
        Dim tbxProductName As New TextBox
        Dim ddlActive As New DropDownList

        tbxProductId = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductId")
        tbxProductName = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductName")
        ddlActive = Me.gvProducts.Rows(e.RowIndex).FindControl("ddlactive")

        If objDatabasePut.ProductUpdate(tbxProductId.Text, _
                                        tbxProductName.Text, _
                                        ddlActive.SelectedValue, _
                                        drProduct.tsValue) Then
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objLiteral.GetLiteralById("msgUpdateProductSuccessful")
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " saved successfully.", "")
        Else
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objDatabasePut.Message
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " failed update.", objDatabasePut.Message, False)
            Exit Sub
        End If

        Me.gvProducts.EditIndex = -1
        LoadProductTable()

    End Sub

Open in new window


Any assistance you would provide is most appreciated.

Much thanks ... David
0
David Bach
Asked:
David Bach
  • 11
  • 7
1 Solution
 
Christopher KileCommented:
Perhaps these lines

<asp:CommandField ButtonType="Button" ShowEditButton="True"
                        ShowInsertButton="True" />

should be changed to this

<asp:CommandField ButtonType="Button" ShowEditButton="True"  />
<asp:CommandField ButtonType="Button" ShowInsertButton="True" />
0
 
David BachAuthor Commented:
Hi cpkilekofp;

I removed the Insert command button and put in an event for Command to see if the Update button press in the gridView control would trigger the Command event - it did not. So, I removed the Command event.

My markup and code look as follows and the Update event is not firing:

            <asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="False" OnRowUpdating="gvProducts_RowUpdating"
                CellPadding="4" ForeColor="#333333" GridLines="None" HorizontalAlign="Center">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:CommandField ButtonType="Button" ShowEditButton="True" />
                    <asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
                    <asp:TemplateField HeaderText="Product Id">
                        <AlternatingItemTemplate>
                            <asp:Label ID="lblProductId" runat="server" Text='<%# Bind("strProductId") %>'></asp:Label>
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbxProductId" runat="server" Text='<%# Bind("strProductId") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblProductId" runat="server" Text='<%# Bind("strProductId") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle Wrap="False" />
                        <ItemStyle Wrap="False" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Product Name">
                        <AlternatingItemTemplate>
                            <asp:Label ID="lblProductName" runat="server" Text='<%# Bind("strProductName") %>'></asp:Label>
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbxProductName" runat="server" Text='<%# Bind("strProductName") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblProductName" runat="server" Text='<%# Bind("strProductName") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle Wrap="False" />
                        <ItemStyle Wrap="False" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Active?">
                        <AlternatingItemTemplate>
                            <asp:Label ID="lblActive" runat="server" Text='<%# Bind("blnActive") %>'></asp:Label>
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddlActive" runat="server">
                                <asp:ListItem Value="0">No</asp:ListItem>
                                <asp:ListItem Value="1">Yes</asp:ListItem>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblActive" runat="server" Text='<%# Bind("blnActive") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle Wrap="False" />
                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                    </asp:TemplateField>
                    <asp:BoundField DataField="dtCreated" HeaderText="Created" ReadOnly="True">
                        <HeaderStyle Wrap="False" />
                        <ItemStyle Wrap="False" />
                    </asp:BoundField>
                    <asp:BoundField DataField="dtUpdated" HeaderText="Updated" ReadOnly="True">
                        <HeaderStyle Wrap="False" />
                        <ItemStyle Wrap="False" />
                    </asp:BoundField>
                    <asp:BoundField DataField="tstValue" HeaderText="Timestamp" ReadOnly="True" Visible="False" />
                </Columns>
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                <SortedAscendingCellStyle BackColor="#FDF5AC" />
                <SortedAscendingHeaderStyle BackColor="#4D0000" />
                <SortedDescendingCellStyle BackColor="#FCF6C0" />
                <SortedDescendingHeaderStyle BackColor="#820000" />
            </asp:GridView>

Protected Sub gvProducts_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvProducts.RowUpdating

        Dim strProductIdOld As String = Session.Item("s_strProductIdOld")
        Dim drProduct As schRegUsers.up_s_ProductAllRow = dsRegUsers.up_s_ProductAll.FindBystrProductId(strProductIdOld)
        Dim tbxProductId As New TextBox
        Dim tbxProductName As New TextBox
        Dim ddlActive As New DropDownList

        tbxProductId = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductId")
        tbxProductName = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductName")
        ddlActive = Me.gvProducts.Rows(e.RowIndex).FindControl("ddlactive")

        If objDatabasePut.ProductUpdate(tbxProductId.Text, _
                                        tbxProductName.Text, _
                                        ddlActive.SelectedValue, _
                                        drProduct.tsValue) Then
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objLiteral.GetLiteralById("msgUpdateProductSuccessful")
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " saved successfully.", "")
        Else
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objDatabasePut.Message
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " failed update.", objDatabasePut.Message, False)
            Exit Sub
        End If

        Me.gvProducts.EditIndex = -1
        LoadProductTable()

    End Sub

Open in new window

Much thanks for the suggestion ... David
0
 
informaniacCommented:
Can you check once if the declarations of other methods are also similar to this.

Protected Sub gvProducts_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvProducts.RowUpdating
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
David BachAuthor Commented:
Hi infomaniac;

I've included the entire code behind page.

Yes, the other events are similar to the RowUpdating event <sigh>.

I feel the solution is going to be so very dumb of me. I have found in my 41 years of software development - the hardest errors to find are often the dumbest ... LOL.

Thank you ... David

Imports BabUtility.BabUtility
Imports DatabaseGet
Imports DatabaseGet.BuzzToolsDBAccess
Imports DatabasePut.BuzzToolsDBAccess

Partial Class Admin_ProductAdmin
    Inherits System.Web.UI.Page

    Dim dsRegUsers As New schRegUsers
    Dim objDatabaseGet As New RegUsers
    Dim objDatabasePut As New ProductPut
    Dim objBaBAudit As New Audit
    Dim objBaBString As New StringMassage
    Dim objLiteral As New LiteralData

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        If Page.IsPostBack Then
            dsRegUsers = Session.Item("s_dsRegUsers")
        End If

        LoadProductTable()
    End Sub

    Protected Sub LoadProductTable()

        Dim strDataKeys(0) As String

        If objDatabaseGet.GetProductAll(dsRegUsers) Then
        Else
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objDatabaseGet.Message
            Exit Sub
        End If

        Me.gvProducts.DataSource = dsRegUsers.up_s_ProductAll
        strDataKeys(0) = "strProductId"
        Me.gvProducts.DataKeyNames = strDataKeys
        Me.gvProducts.DataBind()

        Session.Add("s_dsRegUsers", dsRegUsers)

    End Sub

    Protected Sub gvProducts_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvProducts.RowCancelingEdit

        Me.gvProducts.EditIndex = -1
        Me.gvProducts.DataBind()

    End Sub

    Protected Sub gvProducts_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvProducts.RowEditing

        Me.gvProducts.EditIndex = e.NewEditIndex
        Me.gvProducts.DataBind()

    End Sub

    Protected Sub gvProducts_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvProducts.RowDataBound

        Dim lblActive As New Label
        Dim ddlActive As New DropDownList
        Dim drProduct As schRegUsers.up_s_ProductAllRow
        Dim tbxProductId As New TextBox

        If e.Row.RowType = DataControlRowType.DataRow Then
        Else
            Exit Sub
        End If

        If e.Row.RowState = DataControlRowState.Normal Or
           e.Row.RowState = DataControlRowState.Alternate Then
            lblActive = e.Row.FindControl("lblActive")

            If lblActive.Text = "True" Then
                lblActive.Text = "Yes"
            Else
                lblActive.Text = "No"
            End If

        End If

        If (e.Row.RowState And DataControlRowState.Edit) Then
            ddlActive = e.Row.FindControl("ddlActive")
            tbxProductId = e.Row.FindControl("tbxProductId")
            Session.Add("s_strProductIdOld", tbxProductId.Text)
            drProduct = dsRegUsers.up_s_ProductAll.FindBystrProductId(tbxProductId.Text)

            If drProduct.blnActive Then
                ddlActive.SelectedIndex = 1
            Else
                ddlActive.SelectedIndex = 0
            End If

        End If

    End Sub

    Protected Sub gvProducts_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvProducts.RowDeleting



    End Sub

    Protected Sub gvProducts_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvProducts.RowUpdating

        Dim strProductIdOld As String = Session.Item("s_strProductIdOld")
        Dim drProduct As schRegUsers.up_s_ProductAllRow = dsRegUsers.up_s_ProductAll.FindBystrProductId(strProductIdOld)
        Dim tbxProductId As New TextBox
        Dim tbxProductName As New TextBox
        Dim ddlActive As New DropDownList

        tbxProductId = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductId")
        tbxProductName = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductName")
        ddlActive = Me.gvProducts.Rows(e.RowIndex).FindControl("ddlactive")

        If objDatabasePut.ProductUpdate(tbxProductId.Text, _
                                        tbxProductName.Text, _
                                        ddlActive.SelectedValue, _
                                        drProduct.tsValue) Then
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objLiteral.GetLiteralById("msgUpdateProductSuccessful")
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " saved successfully.", "")
        Else
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objDatabasePut.Message
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " failed update.", objDatabasePut.Message, False)
            Exit Sub
        End If

        Me.gvProducts.EditIndex = -1
        LoadProductTable()

    End Sub

End Class

Open in new window

0
 
Christopher KileCommented:
None of the other event handlers are mentioned in your HTML definition of the GridView.  Try removing the definition of OnRowUpdating (but leave it in your code-behind).
0
 
David BachAuthor Commented:
Hi cpkilekofp;

I removed the OnRowUpdating from the GridView definition - to no avail. I have a break on the Sub statement for the RowUpdating handler ... the process does not stop there.

Thank you ... David
0
 
Christopher KileCommented:
Is your RowEditing handler firing, and does your RowCancelEdit handler fire when you don't think you've canceled?
0
 
David BachAuthor Commented:
Hi cpkilekofp;

The RowEditing and RowCancelEdit fire as they should ... it is only the RowUpdating which doesn't fire. Even the RowDeleting fires.

<shrug> ... very frustrating ... LOL


Much thanks ... David
0
 
Christopher KileCommented:
Can we see the whole page code-behind, please?  You may be modifying the data-binding during edit mode, in which case RowUpdating never fires.
0
 
David BachAuthor Commented:
Hi cpkilekofp;

Yes - here is the code behind.

Much thanks ... David
Partial Class Admin_ProductAdmin
    Inherits System.Web.UI.Page

    Dim dsRegUsers As New schRegUsers
    Dim objDatabaseGet As New RegUsers
    Dim objDatabasePut As New ProductPut
    Dim objBaBAudit As New Audit
    Dim objBaBString As New StringMassage
    Dim objLiteral As New LiteralData

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        If Page.IsPostBack Then
            dsRegUsers = Session.Item("s_dsRegUsers")
        End If

        LoadProductTable()
    End Sub

    Protected Sub LoadProductTable()

        Dim strDataKeys(0) As String

        If objDatabaseGet.GetProductAll(dsRegUsers) Then
        Else
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objDatabaseGet.Message
            Exit Sub
        End If

        Me.gvProducts.DataSource = dsRegUsers.up_s_ProductAll
        strDataKeys(0) = "strProductId"
        Me.gvProducts.DataKeyNames = strDataKeys
        Me.gvProducts.DataBind()

        Session.Add("s_dsRegUsers", dsRegUsers)

    End Sub

    Protected Sub gvProducts_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvProducts.RowCancelingEdit

        Me.gvProducts.EditIndex = -1
        Me.gvProducts.DataBind()

    End Sub

    Protected Sub gvProducts_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvProducts.RowEditing

        Me.gvProducts.EditIndex = e.NewEditIndex
        Me.gvProducts.DataBind()

    End Sub

    Protected Sub gvProducts_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvProducts.RowDataBound

        Dim lblActive As New Label
        Dim ddlActive As New DropDownList
        Dim drProduct As schRegUsers.up_s_ProductAllRow
        Dim tbxProductId As New TextBox

        If e.Row.RowType = DataControlRowType.DataRow Then
        Else
            Exit Sub
        End If

        If e.Row.RowState = DataControlRowState.Normal Or
           e.Row.RowState = DataControlRowState.Alternate Then
            lblActive = e.Row.FindControl("lblActive")

            If lblActive.Text = "True" Then
                lblActive.Text = "Yes"
            Else
                lblActive.Text = "No"
            End If

        End If

        If (e.Row.RowState And DataControlRowState.Edit) Then
            ddlActive = e.Row.FindControl("ddlActive")
            tbxProductId = e.Row.FindControl("tbxProductId")
            Session.Add("s_strProductIdOld", tbxProductId.Text)
            drProduct = dsRegUsers.up_s_ProductAll.FindBystrProductId(tbxProductId.Text)

            If drProduct.blnActive Then
                ddlActive.SelectedIndex = 1
            Else
                ddlActive.SelectedIndex = 0
            End If

        End If

    End Sub

    Protected Sub gvProducts_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvProducts.RowDeleting



    End Sub

    Protected Sub gvProducts_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvProducts.RowUpdating

        Dim strProductIdOld As String = Session.Item("s_strProductIdOld")
        Dim drProduct As schRegUsers.up_s_ProductAllRow = dsRegUsers.up_s_ProductAll.FindBystrProductId(strProductIdOld)
        Dim tbxProductId As New TextBox
        Dim tbxProductName As New TextBox
        Dim ddlActive As New DropDownList

        tbxProductId = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductId")
        tbxProductName = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductName")
        ddlActive = Me.gvProducts.Rows(e.RowIndex).FindControl("ddlactive")

        If objDatabasePut.ProductUpdate(tbxProductId.Text, _
                                        tbxProductName.Text, _
                                        ddlActive.SelectedValue, _
                                        drProduct.tsValue) Then
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objLiteral.GetLiteralById("msgUpdateProductSuccessful")
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " saved successfully.", "")
        Else
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objDatabasePut.Message
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " failed update.", objDatabasePut.Message, False)
            Exit Sub
        End If

        Me.gvProducts.EditIndex = -1
        LoadProductTable()

    End Sub

End Class

Open in new window

0
 
Christopher KileCommented:
In the RowEditing code, you are in fact modifying the binding of the GridView during the Edit Event, which would suppress RowUpdating:

    Protected Sub gvProducts_RowEditing(sender As Object, e As    
        System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvProducts.RowEditing

        Me.gvProducts.EditIndex = e.NewEditIndex
        Me.gvProducts.DataBind()

    End Sub
0
 
David BachAuthor Commented:
Hi cpkilekofp;

If I remove the "Me.gvProducts.DataBind()" within the RowEditing procedure, I do not see the Update/Cancel buttons or the Update template when I click on the Edit button.

I wish it was as simple as you suggested.

Much thanks ... David
0
 
David BachAuthor Commented:
I added a stub for the gridView RowCommand event and set a breakpoint. The Edit and Cancel buttons fire the RowCommand event, however, the Update button does not.

This is becoming so frustrating it's getting almost comical.

David
0
 
Christopher KileCommented:
I suggested that the RowUpdating function was being blocked by the .DataBind() in RowEditing, I said nothing about what might happen if you removed it.  If this was simple, anyone could do it.

Place your .DataBind() in the RowCommand event so that only the Edit command will activate it (take it out of RowEditing).  Then set your breakpoints in RowCommand, RowEditing, and RowUpdating and we'll see what happens.
0
 
David BachAuthor Commented:
Hey cpkilekofp;

LOL ... you are so right ... if this were that easy ... anyone could do it.

Ok ... I put the .DataBind in the RowCommand when the Edit Command is invoked and removed it from RowEditing. Placed breakpoints at RowCommand, RowEditing and RowUpdating.

No breakpoint was triggered when I hit the Update button. Breakpoints were triggered for the RowEditing and RowCommand. Twice for RowCommand (1 for RowEditing and 1 for RowCanceling) and once for RowEditing.

David
0
 
Christopher KileCommented:
OK, I'm offically out of bullets, at least for now.  Hopefully someone else may have a thought.  If I get some time, I'll see if I can duplicate this, but I'm suspecting there's something out there that neither of us have looked at yet.
0
 
David BachAuthor Commented:
Hi cpkilekofp;

I agree with you. This is a web application beneath the web root. I am going to try and create this not as a web application but rather as a website and see if I notice any differences.

The web root is using Framework 3.5. This web application uses Framework 4.0. I don't know if this would cause a problem or not.

I truly appreciate all the suggestions you've given.


Much thanks ... David
0
 
David BachAuthor Commented:
Wow! ... Ok ... I found my error. And yes ... it was DUMB! ... LOL

Each time through the code behind I was loading and binding my product table. So, the RowUpdate event didn't fire because there was no indication of a RowUpdate existing. I subsequently changed the code behind to explicitly bind to the product table during RowCancel and RowEdit events. The RowUpdate event will load a copy of the product table from the database after successfully updating a row. The routine loading of the product table now happens only on the first pass through the code behind.

The code works as I intended it to (and is listed below).

Much thanks to cpkilekofp and informaniac for their time and effort in trying to debug this problem for me.

David
Partial Class Admin_ProductAdmin
    Inherits System.Web.UI.Page

    Dim dsRegUsers As New schRegUsers
    Dim objDatabaseGet As New RegUsers
    Dim objDatabasePut As New ProductPut
    Dim objBaBAudit As New Audit
    Dim objBaBString As New StringMassage
    Dim objLiteral As New LiteralData

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        Me.lblMessage.Text = String.Empty

        If Page.IsPostBack Then
            dsRegUsers = Session.Item("s_dsRegUsers")
        Else
            LoadProductTable()
        End If

    End Sub

    Protected Sub LoadProductTable()

        If objDatabaseGet.GetProductAll(dsRegUsers) Then
        Else
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objDatabaseGet.Message
            Exit Sub
        End If

        BindProducts()

        Session.Add("s_dsRegUsers", dsRegUsers)

    End Sub

    Protected Sub gvProducts_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvProducts.RowCancelingEdit

        Me.gvProducts.EditIndex = -1
        BindProducts()

    End Sub

    Protected Sub gvProducts_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvProducts.RowEditing

        Me.gvProducts.EditIndex = e.NewEditIndex
        BindProducts()

    End Sub

    Protected Sub BindProducts()

        Dim strDataKeys(0) As String

        Me.gvProducts.DataSource = dsRegUsers.up_s_ProductAll
        strDataKeys(0) = "strProductId"
        Me.gvProducts.DataKeyNames = strDataKeys
        Me.gvProducts.DataBind()

    End Sub

    Protected Sub gvProducts_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvProducts.RowDataBound

        Dim lblActive As New Label
        Dim ddlActive As New DropDownList
        Dim drProduct As schRegUsers.up_s_ProductAllRow
        Dim tbxProductId As New TextBox

        If e.Row.RowType = DataControlRowType.DataRow Then
        Else
            Exit Sub
        End If

        If e.Row.RowState = DataControlRowState.Normal Or
           e.Row.RowState = DataControlRowState.Alternate Then
            lblActive = e.Row.FindControl("lblActive")

            If lblActive.Text = "True" Then
                lblActive.Text = "Yes"
            Else
                lblActive.Text = "No"
            End If

        End If

        If (e.Row.RowState And DataControlRowState.Edit) Then
            ddlActive = e.Row.FindControl("ddlActive")
            tbxProductId = e.Row.FindControl("tbxProductId")
            Session.Add("s_strProductIdOld", tbxProductId.Text)
            drProduct = dsRegUsers.up_s_ProductAll.FindBystrProductId(tbxProductId.Text)

            If drProduct.blnActive Then
                ddlActive.SelectedIndex = 1
            Else
                ddlActive.SelectedIndex = 0
            End If

        End If

    End Sub

    Protected Sub gvProducts_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvProducts.RowDeleting



    End Sub

    Protected Sub gvProducts_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvProducts.RowUpdating

        Dim strProductIdOld As String = Session.Item("s_strProductIdOld")
        Dim drProduct As schRegUsers.up_s_ProductAllRow = dsRegUsers.up_s_ProductAll.FindBystrProductId(strProductIdOld)
        Dim tbxProductId As New TextBox
        Dim tbxProductName As New TextBox
        Dim ddlActive As New DropDownList

        tbxProductId = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductId")
        tbxProductName = Me.gvProducts.Rows(e.RowIndex).FindControl("tbxProductName")
        ddlActive = Me.gvProducts.Rows(e.RowIndex).FindControl("ddlactive")

        If objDatabasePut.ProductUpdate(tbxProductId.Text, _
                                        tbxProductName.Text, _
                                        ddlActive.SelectedValue, _
                                        drProduct.tsValue) Then
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objLiteral.GetLiteralById("msgUpdateProductSuccessful")
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " saved successfully.", "")
        Else
            Me.lblMessage.Text = objBaBString.HtmlLineBreak(Me.lblMessage.Text) & objDatabasePut.Message
            objBaBAudit.SaveAudit("Update - Product " & tbxProductId.Text & " failed update.", objDatabasePut.Message, False)
            Exit Sub
        End If

        Me.gvProducts.EditIndex = -1
        LoadProductTable()

    End Sub

End Class

Open in new window

0
 
David BachAuthor Commented:
Reason stated in last post.

Much thanks ... David
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 11
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now