2012-11-07 87 views
2

我有gridview,我在運行時使用datatable添加行作爲datasource.but我想添加刪除命令字段到網格view.I添加並運行它。但我有刪除按鈕在左側position.I想改變刪除按鈕提前到最後自動生成columns.Please幫助me.Thanks後gridview.Means的如何將自動生成的列移動到左側?

+0

你試過了什麼? –

回答

0

這次調職,你需要知道把你生成列在最左邊的部分是什麼:

Move AutoGenerate Columns at LeftMost Part of the GridView Columns

+0

謝謝你。這是非常有用的 –

+0

雖然這可能在理論上回答這個問題,[這將是更可取的](http://meta.stackexchange.com/q/8259)在這裏包括答案的基本部分,並提供該鏈接供參考。 –

0

您可以通過執行以下操作更改訂單: -

YourDataColumn.SetOrdinal(0); 

這使您可以將列移動到無效位置。

希望這會有所幫助。

0
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e){ 

     GridViewRow row = e.Row; 
     // Intitialize TableCell list 
     List<TableCell> columns = new List<TableCell>(); 
     foreach (DataControlField column in GridView1.Columns) 
     { 
      if (row.Cells.Count > 0) 
      { 
      //Get the first Cell /Column 
      TableCell cell = row.Cells[0]; 
      // Then Remove it after 
      row.Cells.Remove(cell); 
      //And Add it to the List Collections 
      columns.Add(cell); 
      } 
     } 

     // Add cells 
     row.Cells.AddRange(columns.ToArray()); 
} 
相關問題