2016-11-14 37 views
0

グリッドビューは、データテーブルと動的にバインドされています。グリッドビュー動的に生成された列

私は

がどのように我々は最後のコマンドフィールドを表示することができます。.. method..AAddOn以下のようにしようが最初に表示された場合、最後のカラムコマンドフィールドAAddOn

に追加する必要がありました。..

<asp:GridView ID="AGridView" runat="server" AutoGenerateColumns="true" style="table-layout:fixed;" Width="2000px" RowStyle-HorizontalAlign="Left"> 
      <EmptyDataTemplate> 
       &nbsp; 
      </EmptyDataTemplate> 
      <asp:CommandField ShowEditButton="True" ItemStyle-Width="80px" EditText="Edit Add On"> 
      <ItemStyle Font-Bold="true" Font-Size="Small" /> 
       <HeaderStyle CssClass="AAddOn" /> 
      </asp:CommandField> 
     </asp:GridView> 

答えて

1

gridviewの場合、定義済みの列が常に最初にレンダリングされ、自動生成された列が右側にレンダリングされます。自動生成された列を左側に移動するには、RowCreatedイベントが必要です。そこで、必要に応じて列の順序を操作できます。以下のコードを使用することができます。

protected void AGridView_RowCreated(object sender, GridViewRowEventArgs e){ 
     List<TableCell> cellColumns = new List<TableCell>(); 
     foreach (DataControlField column in GridView1.Columns) 
     { 
      TableCell cell = e.Row.Cells[0]; 
      e.Row.Cells.Remove(cell); 
      cellColumns.Add(cell); 
     } 

     e.Row.Cells.AddRange(cellColumns .ToArray()); 
} 
+0

ありがとうございました。 – havin

関連する問題