Why my template button field isn't disabled?

Posted on 2009-12-22
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.
e.Row.Cells(9).Enabled = True  'Checked out by the login user then enable the Update button
Protected Sub gvWorkingDocs_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            ' Get the DataKey Value of the grid row
            Dim igcrcNumber As Integer
            igcrcNumber = gvWorkingDocs.DataKeys(e.Row.RowIndex).Value
            Dim test As Integer = dsDocsLogs.Tables(0).Rows.Count

            '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)("gcrcNumber").ToString() = igcrcNumber.ToString() Then
                    If dsDocsLogs.Tables(0).Rows(i)("userId").ToString() = userId Then
                        e.Row.Cells(9).Enabled = True  'Checked out by the login user then enable the Update button
                        e.Row.Cells(8).Enabled = False  ''else, disable the Edit button
                    End If
                End If

        End If
    End Sub

           <asp:GridView ID="gvWorkingDocs" runat="server" AutoGenerateColumns="False" 
                DataKeyNames="gcrcNumber" 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:button ID="editWorkingDoc" runat="server" CommandName="editDoc" 
                            CommandArgument='<%# Eval("gcrcNumber") %>'                              
                            Text="Edit" Enabled="True"></asp:button>
<%--                            <asp:HyperLink ID="editWorkingDoc" runat="server" CommandName="editDoc" 
                            CommandArgument='<% Eval("grcrNumber") %>' NavigateUrl='<%# Eval("DocPath") %>'                             
                            Text="Edit" Enabled="True"></asp:HyperLink>
--%>                        </ItemTemplate>
                            <asp:button id="btnUpdate" runat="server" commandName="selectToUpdate" 
                            CommandArgument='<%# Eval("gcrcNumber") %>' text="Update" Enabled="False"/>
                    <asp:BoundField DataField="Status" HeaderText="Status" 
                        SortExpression="Status" />                                        

                <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

Question by:lapucca
    LVL 12

    Expert Comment

    You may have to use as below.

    e.Row.Cells(8).Controls(0).Enabled = False  // editWorkingDoc is the first control

    Author Comment

    Hummm....  Under e.Row.Cells(8).Controls(0).
    There is no Enabled option.
    Anything else I should try?  Also, did I referece the button correctly?  Thanks.
    LVL 12

    Expert Comment

    oops, sorry for that.  you need to cast that to a Button control and then it will work

    Author Comment

    Ummmm.... How do I cast that to a button?
    LVL 12

    Expert Comment

    ok, use this
    Dim buttEditWorkingDoc As Button
    buttEditWorkingDoc = Cast(e.Row.Cells(8).Controls(0), Button)
    buttEditWorkingDoc.Enabled = False

    Open in new window


    Author Comment

    Umm... Doesn't recognize "Cast" and "Button" in your code.  I tried the following
    CType(e.Row.Cells(9).Controls(0), Button).Enabled = True
    got run time error that
    Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.Button'.
    LVL 12

    Accepted Solution

    Casting filled my mind and I incorrectly typed Cast instead of CType.  Anyways, you got the syntax, sorry for that.  Probably the first item in the ControlsCollection of that Cell has a Literal as its first control.  Try Controls(1) then.  Or you may use like below as well.

    Dim buttEditWorkingDoc As Button
    buttEditWorkingDoc = CType(e.Row.Cells(9).Controls.FindControl("editWorkingDoc"), Button)
    buttEditWorkingDoc.Enabled = False

    Open in new window


    Author Closing Comment


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    731 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