简体   繁体   English

C# 关于数据网格的问题

[英]C# Question about Data Grid

I have the buttons populated in a DataGrid, now I want them to show on the right of the data not the default position (left).我在 DataGrid 中填充了按钮,现在我希望它们显示在数据的右侧,而不是默认的 position(左)。 How can I achieve this?我怎样才能做到这一点?

Thank you谢谢

<asp:DataGrid runat="server" ID="myDataGrid"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" 
GridLines="None">
<Columns>
   <asp:TemplateColumn>
       <ItemTemplate>
          <asp:Button runat="server" Text="Delete"/>
        </ItemTemplate>
   </asp:TemplateColumn>
</Columns>

PS: I am binding the data to an array PS:我将数据绑定到一个数组

  myDataGrid.DataSource = vals;
  myDataGrid.DataBind();

You can define a column for the array of string before the button column like this您可以像这样在按钮列之前为字符串数组定义一列

<Columns>
   <asp:TemplateColumn>
       <ItemTemplate>
          <asp:Label ID="someLabelId" runat="server" 
                                              Text='<%# Container.DataItem %>' />
        </ItemTemplate>
   </asp:TemplateColumn>

   <asp:TemplateColumn>
       <ItemTemplate>
          <asp:Button runat="server" Text="Delete"/>
        </ItemTemplate>
   </asp:TemplateColumn>
</Columns>

and set AutoGenerateColumns="false" for the DataGrid并为DataGrid设置AutoGenerateColumns="false"

<asp:DataGrid runat="server" ID="myDataGrid" AutoGenerateColumns="false"

use ItemStyle HorizontalAlign="Right" as defined at: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.itemstyle.aspx使用 ItemStyle HorizontalAlign="Right" 定义于: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.itemstyle.aspx

try:尝试:

&ltasp:TemplateColumn ItemStyle-HorizontalAlign="Right">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM