• 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
                    Else
                        e.Row.Cells(8).Enabled = False  ''else, disable the Edit button
                    End If
                End If
            Next

        End If
    End Sub



           <asp:GridView ID="gvWorkingDocs" runat="server" AutoGenerateColumns="False" 
                onrowcommand="gvWorkingDocs_RowCommand"
                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" />
                <Columns>
                    <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>
                    <asp:BoundField DataField="LongName" HeaderText="LongName" ReadOnly="True" 
                        SortExpression="LongName" Visible="False" />
                    
                    <asp:TemplateField>
                        <ItemTemplate>
                            <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:TemplateField>
                      
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:button id="btnUpdate" runat="server" commandName="selectToUpdate" 
                            CommandArgument='<%# Eval("gcrcNumber") %>' text="Update" Enabled="False"/>
                        </ItemTemplate>
                    </asp:TemplateField>
                      
                    <asp:BoundField DataField="Status" HeaderText="Status" 
                        SortExpression="Status" />                                        

                </Columns>
                <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" />
            </asp:GridView>

Open in new window

0
lapucca
Asked:
lapucca
  • 4
  • 4
1 Solution
 
CB_ThirumalaiCommented:
You may have to use as below.

e.Row.Cells(8).Controls(0).Enabled = False  // editWorkingDoc is the first control
0
 
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.
0
 
CB_ThirumalaiCommented:
oops, sorry for that.  you need to cast that to a Button control and then it will work
0
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?
0
 
CB_ThirumalaiCommented:
ok, use this
Dim buttEditWorkingDoc As Button
buttEditWorkingDoc = Cast(e.Row.Cells(8).Controls(0), Button)
buttEditWorkingDoc.Enabled = False

Open in new window

0
 
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'.
0
 
CB_ThirumalaiCommented:
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

0
 
lapuccaAuthor Commented:
Thanks!
0
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