Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

why are columns still enabled when set to false?

Posted on 2014-09-19
11
Medium Priority
?
114 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 13

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 27

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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 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