[英]Align Asp.net Buttons under GridView
我有一個帶有三個按鈕的GridView。 我試圖弄清楚如何對齊它們,以便第一個按鈕的左側邊緣與GridView的左側邊緣對齊,第二個按鈕位於GridView的正下方,第三個按鈕的右側邊緣與GridView的右側邊緣對齊。 如果GridView的寬度擴大,我希望按鈕與GridView保持對齊。 現在,這些按鈕水平“聚集”在一起,並向左對齊。 這是我想要的草圖。
有很多方法可以做到這一點。 您可以將按鈕放入網格的頁腳中,也可以在與網格相同寬度的網格下放置一個較大的div或表格。
我將它們放在頁腳模板中,如下所示:(pseudo)
div width 100%
div 33%
button 1 (align it to left)
div 33%
button 2 (align it to center
div 33%
button 3 (align it to right
如果您知道固定尺寸,可以使用固定尺寸
編輯:剛注意到網格下的大差距,您可以像這樣
div 100%
grid (assuming 100% also)
div (100%)
and div 33% with buttons go here
您可以嘗試使用此代碼
<FooterTemplate>
<table>
<tr>
<td class=""><asp:Button ID="Btn1" runat="server" Text="Btn1"/>
</td>
<td class=""><asp:Button ID="Btn2" runat="server" Text="Btn2"/>
</td>
<td class=""><asp:Button ID="Btn3" runat="server" Text="Btn3"/>
</td>
</tr>
</table>
</FooterTemplate>
您可以將樣式屬性添加到表的單元格中
text-align: center;
text-align: left;
text-align: right;
如何將Gridview和Button放在表的單獨行中?
這是內聯樣式的示例:
<table>
<tr>
<td colspan="3" style="width: 100%">
<asp:GridView ID="GridView1" ShowHeader="false">
...
</asp:GridView>
</td>
</tr>
<tr>
<td style="width: 33%; text-align: left">
<asp:Button ID="button1" runat="server" />
</td>
<td style="width: 33%; text-align: center">
<asp:Button ID="button2" runat="server" />
</td>
<td style="width: 33%; text-right">
<asp:Button ID="button3" runat="server" />
</td>
</tr>
</table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.