Solved

why are columns still enabled when set to false?

Posted on 2014-09-19
11
112 Views
Last Modified: 2014-10-01
experimental web page with gridview
columns 1,2,3,8,9,10,11,12 should be disabled on Saturday or Sunday.
columns 1,2,3 are not enabled in edit mode but all columns are enabled after 3 when it is Saturday or sunday.
why do the first three work but the next ones don't?
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.DataControlFieldCollection" %>
<%@ Import Namespace="System.Web.UI.WebControls.DataControlField" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Web.UI.Htmlcontrols" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">  
    Sub Page_Load() Handles Me.Load
        
    End Sub
    Sub CustomersGridView_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)

        ' Get the country for the row being edited. For this example, the
        ' country is contained in the seventh column (index 6). 
        Dim storeday As String = CustomersGridView.Rows(e.NewEditIndex).Cells(3).Text

        ' For this example, cancel the edit operation if the user attempts
        ' to edit the record for holidays. 
        If storeday = "Holiday" Then

            ' Cancel the edit operation.
            e.Cancel = True
            Message.Text = "You cannot edit this record."
        Else
            Message.Text = ""
            

        End If

    End Sub
    Sub CustomersGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

        ' Get the column for the row being edited. For this example, the
        ' date type is contained in the 4th column (index 3). 
        If e.Row.RowType = DataControlRowType.DataRow Then
        'find if it is Saturday or sunday and disable collecting PTO time
            Dim storeday As String = e.Row.Cells(3).Text
       
            e.Row.Cells(0).Enabled = True
            e.Row.Cells(1).Enabled = False
            e.Row.Cells(2).Enabled = False
            e.Row.Cells(3).Enabled = False
             
            If storeday = "Holiday" Then
            
            ElseIf storeday = "Saturday" Or storeday = "Sunday" Then
                e.Row.Cells(8).Enabled = False
                e.Row.Cells(9).Enabled = False
                e.Row.Cells(10).Enabled = False
                e.Row.Cells(11).Enabled = False
                e.Row.Cells(12).Enabled = False

            End If
        End If
    End Sub

    
  
  
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
     <h3>GridView RowEditing Example</h3>

      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>

      <br/>
    <div>
     
       <!-- The GridView control automatically sets the columns     -->
      <!-- specified in the datakeynames property as read-only.    -->
      <!-- No input controls are rendered for these columns in     -->
      <!-- edit mode.                                              -->
      <asp:gridview id="CustomersGridView" 
        datasourceid="SqlDataSource1" 
        autogeneratecolumns="true"
        autogenerateeditbutton="true"
        allowpaging="true" 
        datakeynames="ID"
        onrowdatabound="CustomersGridView_RowDataBound"
        onrowediting="CustomersGridView_RowEditing"  
         
        runat="server">
      </asp:gridview>

     

      
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            SelectCommand='SELECT [ID],[WORKDATE], [STARTDAY], [STARTTIME], [ENDTIME], [STARTLUNCH], [ENDLUNCH], [PTODETAIL], [PTOPAID], [PTOUNPAID], [COMPANYPTO], [COMPANYPTOPAID], [SYMITARCODE] FROM [EmployeeAccumInfo]' 
            ConnectionString="<%$ ConnectionStrings:cudataConnectionString %>"></asp:SqlDataSource>
            
    </div>
    </form>
</body>

</html>

Open in new window

0
Comment
Question by:javagair
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 

Author Comment

by:javagair
ID: 40333836
if I set the same columns to turn red they do, they just won't disable
0
 
LVL 12

Expert Comment

by:jitendra patil
ID: 40334126
do you want to make it visible or invisible ?

as you said enable or disable will still be seen on the screen, try using the visible property.
0
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 40334297
Have you confirmed that column 3 does have the text you are expecting? From the your sqldatasource, column four matches starttime.
0
Independent Software Vendors: 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!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 40334328
You should try to disable the controls in the cells, and not the cells.
0
 

Author Comment

by:javagair
ID: 40337177
have a breakpoint In and know what is in each column, when I added autoedit button every thing moves back one because button is now 0.

bob learned
which controls would you disable, find none in literature that would do this.

will try the visible

thanks

gary
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40339913
How is your GridView defined in HTML?
0
 

Author Comment

by:javagair
ID: 40342222
<asp:gridview id="CustomersGridView"
        datasourceid="SqlDataSource1"
        autogeneratecolumns="true"
        autogenerateeditbutton="true"
        allowpaging="true"
        datakeynames="ID"
        onrowdatabound="CustomersGridView_RowDataBound"
        onrowediting="CustomersGridView_RowEditing"  
         
        runat="server">
      </asp:gridview>

     

     
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            SelectCommand='SELECT [ID],[WORKDATE], [STARTDAY], [STARTTIME], [ENDTIME], [STARTLUNCH], [ENDLUNCH], [PTODETAIL], [PTOPAID], [PTOUNPAID], [COMPANYPTO], [COMPANYPTOPAID], [SYMITARCODE] FROM [EmployeeAccumInfo]'
            ConnectionString="<%$ ConnectionStrings:cudataConnectionString %>"></asp:SqlDataSource>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40344071
With auto-generated columns, try setting the column read-only, instead of the cell.

Tip of the Day–Set ReadOnly for AutoGenerate Columns in GridView
http://geekswithblogs.net/dotNETvinz/archive/2013/02/04/tip-of-the-dayndashset-readonly-for-autogenerate-columns-in-gridview.aspx
0
 

Accepted Solution

by:
javagair earned 0 total points
ID: 40346483
change all fields to be asp:templatefield and the enable and disable work just fine
only using a boundfields and enable causes a problem if you intermix enable and disabled fields.

thanks

gary
0
 

Author Closing Comment

by:javagair
ID: 40354161
although the other comments made me think about how the gridview works and through interpolation of answers lead to the correct answer, the only solution is the one I did
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

710 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