Solved

why are columns still enabled when set to false?

Posted on 2014-09-19
11
109 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
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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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 …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

24 Experts available now in Live!

Get 1:1 Help Now