Solved

why are columns still enabled when set to false?

Posted on 2014-09-19
11
111 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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