[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 790
  • Last Modified:

formatting button style within an EditCommandColumn

I have the following style that I apply to all the buttons on my page.  I have not been able to format the buttons in the Datagrid's EditCommand Column.  My only options seem to be basic text or hyperlink or image.  I would like to apply the below effects so that my page design is the same accross the board.  Please help!!

--------------------------------------------------------------------------------------------------------------
<asp:Button id=btnDel Text="Delete" onmouseup="this.style.color='black';
this.style.backgroundColor='lightblue'" onmousedown="this.style.color='white';
this.style.backgroundColor='red'" onmouseover="this.style.color='black';
this.style.backgroundColor='lightblue'" style="WIDTH: 50px;      COLOR: white;
HEIGHT: 24px; BACKGROUND-COLOR: steelblue" onmouseout="this.style.color='white';
this.style.backgroundColor='steelblue'" CommandName="Delete" Runat="server"></asp:Button>
--------------------------------------------------------------------------------------------------------------
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit">
</asp:EditCommandColumn>
--------------------------------------------------------------------------------------------------------------
0
Robb Hill
Asked:
Robb Hill
  • 3
  • 2
1 Solution
 
recklezCommented:
I add the styles programatically for the EditCommandColumn buttons.

In your datagrid tag add an OnItemCreated attribute.
<asp:DataGrid ID="myDatagrid" runat="server" OnItemCreated="myDatagrid_ItemCreated" AutoGenerateColumns="false" ... </asp:DataGrid>



In your code implent the function with the name you specified (myDatagrid_ItemCreated) that handles the ItemCreated Event

Public Sub myDatagrid_ItemCreated(ByVal Sender As Object, ByVal e As DataGridItemEventArgs)

   'If this is an edit row.
   If (e.Item.ItemType = ListItemType.EditItem) Then
            'Add CSS style to the buttons
            Dim updateButton As Button = CType(e.Item.Cells(5).Controls(0), Button)
            updateButton.CssClass = "submit1"

            Dim cancelButton As Button = CType(e.Item.Cells(5).Controls(2), Button)
            cancelButton.CssClass = "submit1"

            Dim deleteButton As Button = CType(e.Item.Cells(6).Controls(0), Button)
            deleteButton.CssClass = "submit1"
            deleteButton.Attributes.Add("onClick", "return confirm('Are you sure you want to delete this Manager?');")
    End If

End Sub

Note that you must change the index of the Cells() depending on how many columns you have on your datagrid.
0
 
Robb HillSenior .Net DeveloperAuthor Commented:
This is pretty neat.....more specifically though....can I use the styles I mentioned above...when I am in my css editor I do not see the onmouseover and such events.....am I doing something wrong or are they unavailabe from a stylesheet.

Thanks.
0
 
recklezCommented:
You could use the styles mention above. If you want to register an event on the button like onmouseover or onmousedown
simmply add an attribute to the button like

myButton.Attributes.Add("onmouseover","this.style.color='black'")

You will not be able to view these effects in an editor because they are rendered at runtime.
0
 
Robb HillSenior .Net DeveloperAuthor Commented:
Very nice...I have been wondering what the trick was to this.  Thanks a million ...I mean 500 :D
0
 
recklezCommented:
You are very welcome robbhill!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now