Solved

why are columns still enabled when set to false?

Posted on 2014-09-19
11
106 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
Comment Utility
if I set the same columns to turn red they do, they just won't disable
0
 
LVL 12

Expert Comment

by:Jitendra Patil
Comment Utility
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 25

Expert Comment

by:Shaun Kline
Comment Utility
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
Comment Utility
You should try to disable the controls in the cells, and not the cells.
0
 

Author Comment

by:javagair
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
How is your GridView defined in HTML?
0
 

Author Comment

by:javagair
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

13 Experts available now in Live!

Get 1:1 Help Now