开发者

C# Question about Data Grid

I have the buttons populated in a DataGrid, now I want them to show on the right o开发者_StackOverflow中文版f the data not the default position (left). 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

  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

<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

try:

<asp:TemplateColumn ItemStyle-HorizontalAlign="Right">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜