2

IDE: Microsoft Visual Studio Platform: C#.net

Hi, I am trying to add a custom button with image for a cell of gridview in c#.net, but not successful in achieving that. Any suggestions?

Harsh
  • 83
  • 3
  • 10

1 Answers1

0

you can do it by two ways in gridview. 1 without css

<asp:TemplateField HeaderText="Test">
     <ItemTemplate>
     <asp:Button runat="server" ID="test" Text="upload" Style="background-color: green"/>
     </ItemTemplate>
     <FooterStyle />
     <HeaderStyle />
     <ItemStyle Width="30%" />
</asp:TemplateField>

2nd way, same code but replace the style attribute with CssClass="buttonBackground"

<asp:TemplateField HeaderText="Test">
     <ItemTemplate>
     <asp:Button runat="server" ID="test" Text="upload" CssClass="buttonBackground"/>
     </ItemTemplate>
     <FooterStyle />
     <HeaderStyle />
     <ItemStyle Width="30%" />
</asp:TemplateField>

CSS

.buttonBackground
{
    background-image: url(../Images/backgroundImage.png);
    background-repeat: repeat-x;
}
Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73