Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Why my template button field isn't disabled?

Posted on 2009-12-22
Medium Priority
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
  • 4
  • 4
LVL 12

Expert Comment

ID: 26108309
You may have to use as below.

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

Author Comment

ID: 26108657
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

ID: 26108701
oops, sorry for that.  you need to cast that to a Button control and then it will work
Technology Partners: 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!


Author Comment

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

Expert Comment

ID: 26108781
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

ID: 26108849
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

CB_Thirumalai earned 2000 total points
ID: 26108997
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

ID: 31669191

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
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.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

571 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