A A A
C  C  Off 

Conditionally Hide a Button on a Table Control Row

There comes a time when a record reaches a stage where no more editing should be performed.

In this example, I have set up a dummy invoice, marked it as paid and using a small amount of code in the controls file, removed the edit button from appearing on the row.

This is a very simple process and can be accomplished like so:

 

Protected Overrides Sub Control_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender 
            MyBase.Control_PreRender(sender,e)
            If Me.DataSource IsNot Nothing Then
                Me.TableControlRowEditButton.Visible = Not Me.DataSource.paid
            End If
        End Sub

 

Using the above code, we first make a call to the base method and make any alterations after the call has been completed.

First, we check that the datasource is not nothing (null), then determine that the buttons visibility should equal the opposite of a boolean field (paid).

If the datasource returns paid as false, the button will be visible and clickable, else it will be hidden so that no further amendments can be made.

Figure 1 below illustrates this perfectly: 

 Success!

  • Facebook
  • Twitter
  • Digg It!
Leave a comment
Close

Enter your details and click subscribe to sign up to our newsletter

 *
   
 
 

* Required Field

Subscribe