• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Why my template button field isn't disabled?

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

  • 4
  • 4
1 Solution
You may have to use as below.

e.Row.Cells(8).Controls(0).Enabled = False  // editWorkingDoc is the first control
lapuccaAuthor Commented:
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.
oops, sorry for that.  you need to cast that to a Button control and then it will work
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

lapuccaAuthor Commented:
Ummmm.... How do I cast that to a button?
ok, use this
Dim buttEditWorkingDoc As Button
buttEditWorkingDoc = Cast(e.Row.Cells(8).Controls(0), Button)
buttEditWorkingDoc.Enabled = False

Open in new window

lapuccaAuthor Commented:
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'.
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

lapuccaAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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