Results 1 to 4 of 4

Thread: [2005] set button display to none

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    [2005] set button display to none

    Hi All,

    Below is my commandfield embeded with a edit button. How to set the button display into none ?

    It work fine in vs 2003 by using style = "display:none"
    but it doesn't work in vs 2005.

    asp Code:
    1. <asp:CommandField ButtonType="Button" ShowEditButton="false" ShowHeader="True"  >
    2.                         <ItemStyle HorizontalAlign="Center" Width="15px" Wrap="True" />
    3.                    
    4.                     </asp:commandfield>

    Thanks a lot.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] set button display to none

    You can do it from the codebehind by setting the column's Visible property to false.

    If you set it in the CSS, then the button is still 'sent' to the client, making the button visible in the HTML source, which is a waste. You should not send it to the client at all, and for that you can set the .Visible property of the column so that it doesn't render.

  3. #3

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [2005] set button display to none

    Thanks Mendnak,

    I has changed my templates to templateField.
    It was solved my problems.

    But now I'm facing another problem.

    javascript Code:
    1. <script language="javascript" type="text/javascript">
    2.         function OnChange_Chk(currCheckBox){
    3.  
    4.             var selectedColor = 'Lavender';
    5.             var grid = document.getElementById("<%= grdStatusMaster.ClientID %>");
    6.             var Cell;
    7.             var pushButtonColumnIndex = 4;            
    8.             var currRow = currCheckBox.parentElement.parentElement;
    9.             var currPushButton = currRow.cells[pushButtonColumnIndex].childNodes[0];
    10.            
    11.             if(currCheckBox.checked){
    12.                 currRow.oldBackgroundColor = currRow.style.backgroundColor;
    13.                 currRow.style.backgroundColor=selectedColor;
    14.                
    15.                 if (grid.rows.length > 0)
    16.             {
    17.                
    18.  
    19.                 for (i=0; i<grid.rows.length; i++)
    20.                 {
    21.                     cell = grid.rows[i].cells[4];
    22.                     for (j=0; j<cell.childNodes.length; j++)
    23.                     {        
    24.                        
    25.                         if (cell.childNodes[j].type =="submit")
    26.                         {
    27.                             cell.childNodes[j].style.display = "none";
    28.                         }
    29.                     }
    30.                 }
    31.             }
    32.              currPushButton.style.display = "block";
    33.             }else{
    34.                 currRow.style.backgroundColor= currRow.oldBackgroundColor;
    35.                 currPushButton.style.display = "none";
    36.             }
    37.             uncheckOthers(currCheckBox);
    38.         }
    39.         function uncheckOthers(id)
    40.     {        
    41.  
    42.  
    43.         var elm = document.getElementsByTagName('input');        
    44.         for(var i = 0; i < elm.length; i++)
    45.         {                            
    46.             if(elm.item(i).id.substring(id.id.lastIndexOf('_')) == id.id.substring(id.id.lastIndexOf('_')))
    47.             {
    48.                 if( elm.item(i).type == "checkbox" && elm.item(i)!=id){
    49.                     elm.item(i).checked = false;
    50.                     }
    51.             }
    52.            
    53.         }
    54.     }        
    55.  
    56. </script>

    asp Code:
    1. Protected Sub grdStatusMaster_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles grdStatusMaster.RowCancelingEdit
    2.  
    3.         grdStatusMaster.EditIndex = -1
    4.         grdStatusMaster.Columns.Item(4).ItemStyle.Width = 15
    5.         grdStatusMaster.Width = 450
    6.         Me.grdStatusMaster.DataSource = (CType(Session("myDatatable"), DataTable)).DefaultView
    7.         Me.grdStatusMaster.DataBind()
    8.  
    9.     End Sub
    10.  
    11. Protected Sub grdStatusMaster_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles grdStatusMaster.RowEditing
    12.  
    13.         With grdStatusMaster
    14.  
    15.             .EditIndex = e.NewEditIndex
    16.             .Width = 560
    17.             .Columns.Item(4).ItemStyle.Width = 125
    18.  
    19.             If Me.IsPostBack Then
    20.  
    21.                 Me.grdStatusMaster.DataSource = (CType(Session("myDatatable"), DataTable)).DefaultView
    22.                 Me.grdStatusMaster.DataBind()
    23.                 Dim descTB As TextBox
    24.                 Dim rowCheckbox As CheckBox
    25.                 Dim strScript As String
    26.                 descTB = .Rows(.EditIndex).Cells(2).FindControl("txtdesc")
    27.                 rowCheckbox = .Rows(.EditIndex).Cells(0).FindControl("ChkSelect")
    28.  
    29.                 strScript = "<script language=""JavaScript"">" & vbCrLf & _
    30.                              vbTab & "document.getElementById('" & descTB.ClientID & "')" & ".focus();" & _
    31.                               vbCrLf & vbTab & "document.getElementById('" & descTB.ClientID & "')" & ".select();" & _
    32.                               vbCrLf & vbTab & "document.getElementById('" & rowCheckbox.ClientID & "')" & ".checked = true;" & _
    33.                              vbCrLf & "<" & "/script>"
    34.                 Page.ClientScript.RegisterStartupScript(GetType(String), "HighLightText", strScript)
    35.  
    36.             End If
    37.         End With
    38.  
    39.     End Sub

    The code above will only allow user to check one row in gridview ( Success )
    and also make the button be "none" or "block" ( partially success )

    Now my problem is the edit button work nicely and also the cancel button.
    The problem is it will not effect to update button.


    how to rectify my problem ?

    Thanks a million :-)
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] set button display to none

    Are you handling the RowUpdating event? What does the markup look like?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width