My button is still not enabled even when I set it to enabled

Posted on 2009-12-23
Last Modified: 2012-05-08
Hi, I'm using vs2008, .net
The breakpoint is set at this loc and it's executed but the update button is still not ablled.  How can I address this?  thank you.
both buttons are not abled even code is executed and I can see the property is set to be abled.  I refresh the page again and nothing changes.  

Protected Sub gvWorkingDocs_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvWorkingDocs.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            ' Get the DataKey Value of the grid row
            Dim newFileName As String
            newFileName = gvWorkingDocs.DataKeys(e.Row.RowIndex).Value.ToString()
            Dim updateButton As System.Web.UI.WebControls.Button
            Dim editButton As System.Web.UI.WebControls.Button

            'If a match is found then the doc is checked out
            For i As Integer = 0 To dsDocsLogs.Tables(0).Rows.Count - 1
                If dsDocsLogs.Tables(0).Rows(i)("NewFileName").ToString() = newFileName Then
                    'Fill in the status info
                    e.Row.Cells(8).Text = "Checked out by " + dsDocsLogs.Tables(0).Rows(i)("userName").ToString() & _
                    " @" + dsDocsLogs.Tables(0).Rows(i)("dateTime").ToString()

                    'Enable or Disable Update and Edit button
                    If dsDocsLogs.Tables(0).Rows(i)("userId").ToString() = userId Then
                        updateButton = CType(e.Row.FindControl("editWorkingDoc"), System.Web.UI.WebControls.Button)
                        updateButton.Enabled = True
                    Else 'else, disable the Edit button
                        editButton = CType(e.Row.FindControl("btnUpdate"), System.Web.UI.WebControls.Button)
                        editButton.Enabled = False
                    End If
                End If

        End If
    End Sub

Open in new window

Question by:lapucca

    Author Comment

    Here is the code for the gridview
    <asp:GridView ID="gvWorkingDocs" runat="server" AutoGenerateColumns="False" 
                    DataKeyNames="NewFileName" DataSourceID="SqlDataSource1" CellPadding="4" 
                    ForeColor="Black" BackColor="#AFE9CC" BorderColor="Black" 
                    BorderStyle="Solid" BorderWidth="1px" style="margin-left: 0px" 
                        AllowSorting="True" AllowPaging="True" >
                    <RowStyle BackColor="#FFFF99" ForeColor="#000000" HorizontalAlign="Left" 
                        BorderStyle="Ridge" />
                        <asp:BoundField DataField="gcrcNumber" HeaderText="GCRC" ReadOnly="True" 
                            SortExpression="gcrcNumber" Visible="False" />
                        <asp:BoundField DataField="IRBNum" HeaderText="IRB #" ReadOnly="True" 
                            SortExpression="IRBNum" Visible="False" />
                        <asp:BoundField DataField="CtuApp_ID" HeaderText="Application ID" 
                            SortExpression="CtuApp_ID" Visible="False" />
                        <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
                        <asp:BoundField DataField="NewFileName" HeaderText="FileName" 
                            SortExpression="NewFileName" Visible="False" />
                        <asp:BoundField DataField="OriginalFileName" HeaderText="File Name" 
                            SortExpression="OriginalFileName" />
                        <asp:BoundField DataField="Date" HeaderText="Modified Date" 
                            SortExpression="Date" ItemStyle-Wrap="False" ><ItemStyle Wrap="False"></ItemStyle>
                        <asp:BoundField DataField="LongName" HeaderText="LongName" ReadOnly="True" 
                            SortExpression="LongName" Visible="False" />
                        <asp:BoundField DataField="Status" HeaderText="Status" 
                            SortExpression="Status" />                                        
                                <asp:button ID="editWorkingDoc" runat="server" CommandName="editDoc" 
                                CommandArgument='<%# (CType(Container, GridViewRow).RowIndex).ToString() + "," + Eval("NewFileName") + "," + Eval("DocPath") %>'                   
                                Text="Edit" Enabled="True"></asp:button>                        
                                <asp:button id="btnUpdate" runat="server" commandName="selectToUpdate" 
                                CommandArgument='<%# Eval("NewFileName") %>' text="Update" Enabled="False"/>
                    <FooterStyle BackColor="#EEEEE0" Font-Bold="True" ForeColor="#000000" BorderStyle="Solid" BorderWidth="1px" BorderColor="Black" />
                    <PagerStyle BackColor="#ffffff" ForeColor="#000000" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#EEEEE0" Font-Bold="True" ForeColor="Black" BorderWidth="1px" />
                    <HeaderStyle BackColor="#CCFFCC" Font-Bold="True" ForeColor="Black" 
                        BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" />
                    <EditRowStyle BackColor="#AFE9CC" />
                    <AlternatingRowStyle BackColor="#FFFFCC" BorderWidth="1px" BorderStyle="Solid" 
                        BorderColor="Black" />

    Open in new window

    LVL 35

    Expert Comment

    by:Miguel Oz
    Can you put breakpoints at line 17 in you question code snippet?
    Tell me what these values are when program stop in the breakpoint:

    If not hit in the breakpoint try line 11. you may have a problem when comparing the strings. (eg. case, match exactly)
    LVL 9

    Accepted Solution


    updateButton = CType(e.Row.FindControl("editWorkingDoc"), System.Web.UI.WebControls.Button)

    Shouldnt that be

    updateButton = CType(e.Row.FindControl("btnUpdate"), System.Web.UI.WebControls.Button)

    And samething for EditButton

    Author Comment

    These are hit alright.  I copy the value from debug anyway just to show you.  Yeah, the loc is definitly executed for setting the updateButton to Enabled but it still shows up disabled.  Thanks.

                dsDocsLogs.Tables(0).Rows(i)("NewFileName").ToString()       "300-4A-09-1CTU_HS-09-00489_10-22-09-10292009135102.doc"      String

                newFileName      "300-4A-09-1CTU_HS-09-00489_10-22-09-10292009135102.doc"      String

                dsDocsLogs.Tables(0).Rows(i)("userId").ToString()      "AlphaDavis"      String

    userId = "AlphaDavis"

    Author Closing Comment

    Good catch!  Yeah, the stupid bug kept me working on this for like a couple hours already!  Thank you!
    LVL 9

    Expert Comment

    Really Glad that i was able to help you out.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now