2009-06-26 78 views

回答

4

只需將您的列定義添加到gridview的部分即可。你的自動生成的列應該顯示在這個列的左邊。

<asp:gridview AutoGenerateColumns="true" ... > 
    <columns> 
     <asp:hyperlink ... /> 
    </columns> 
</asp:gridview> 
+0

感謝。這將是HyperLinkField不是常規的超鏈接控件,它會給出錯誤。 – 2009-06-26 22:08:46

2

我發現自動生成的列顯示在右邊。如果你想他們是在左邊,你必須將代碼添加到其刪除和RowCreated事件重新添加所有列,就像這樣:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) 
    { 
     GridViewRow row = e.Row; 
     List<TableCell> columns = new List<TableCell>(); 

     foreach (DataControlField column in GridView1.Columns) 
     { 
      TableCell cell = row.Cells[0]; 
      row.Cells.Remove(cell); 
      columns.Add(cell); 
     } 

     row.Cells.AddRange(columns.ToArray()); 
    } 

找到的文章在這裏:http://geekswithblogs.net/dotNETvinz/archive/2009/06/03/move--autogenerate-columns-at-leftmost-part-of-the-gridview.aspx