2010-05-06 67 views
2

鑑於GridView列的以下標記,爲什麼我的圖像按鈕顯示爲左對齊?ImageButton未與中心對齊

<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> 

回答

1

你可以使用css嗎?你可能有更好的運氣使用下面的CSS樣式。

可以說x-m.png的寬度是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> 
+0

最後沒有工作我試過 - 我會稍後再試。 – ProfK 2010-05-07 04:35:08

+0

是的,你是對的 - 我更新了我的答案。您必須設置按鈕和包含塊的樣式。 – Steve 2010-05-07 12:54:46