ImageButton is not centered

Given the following markup for the GridView column, why are my image buttons displayed left-aligned?

<ItemStyle HorizontalAlign="Center" Width="55px" />
<ItemTemplate>
    <asp:ImageButton ID="removeButton" runat="server" 
        ImageUrl="~/Images/Icons/x-m.png" 
        CommandArgument='<%# Eval("ResourceId") %>' 
        AlternateText="Remove Button" 
        onclick="removeButton_Click" />
</ItemTemplate>

      

+2


a source to share


1 answer


Can you use css? You might be in luck with a nice styling using the following css.

Let's assume the width of xm.png is 25px;



.X { width: 55px; }
.Y { display: block; margin: 0 auto;  width: 25px; } 

<ItemStyle cssClass="X" />
<ItemTemplate>
        <asp:ImageButton ID="removeButton" runat="server" 
        ImageUrl="~/Images/Icons/x-m.png" 
        CommandArgument='<%# Eval("ResourceId") %>' 
        AlternateText="Remove Button" 
        onclick="removeButton_Click"
        cssClass="Y"/>
</ItemTemplate>

      

+1


a source







All Articles