views:

23

answers:

1

Given the following markup for a GridView column, why are my image buttons showing up as 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>
A: 

Can you use css? You might have better luck styling using the following css.

Lets say width of x-m.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>
Steve
Didn't work last I tried - I will try again later.
ProfK
Yes, you're right - I updated my answer. You have to style both the button and containing block.
Steve