2013-05-07 29 views
0

我有一個GridView(GridviewProduct),因爲我有一個模板字段列鏈接按鈕作爲從購物車中刪除和另一個模板字段列作爲數量和其他三個字段是像ProductName,ProductPrice和ProductBrand一樣的boundField。看起來如下: enter image description here在gridview中移動模板字段和綁定字段之間的列

我想將數量列移動到右側gridview的末尾。當我使用此代碼它給我一個錯誤:

Insertion index was out of range

var Quantity = GridViewProduct.Columns[1]; 
GridViewProduct.Columns.RemoveAt(1); 
GridViewProduct.Columns.Insert(5, Quantity); 

請幫助。

+0

你需要columno 1和2?如果不是,那麼首先設置autogeneratecolumn = false – Anuj 2013-05-07 11:48:15

+0

@Anuj:當我做了我的boundField列消失..我有一個來自linq2sql的數據源。 – 2013-05-07 11:53:50

回答

1

您的要求可以在GridView的RowCreated事件實現

+0

謝謝kundan ..當我正在尋找答案時,我遇到了ITemplate接口,從服務器端添加列到gridview將移動列將有幫助..我的意思是這種解決方案是優秀的,但會嗎? – 2013-05-08 09:06:24

+0

如果我還沒有找到你的答案..我正在爲它! – 2013-05-08 11:23:51

1

如果你有5列並刪除其中的一個,你還剩4個。新的最後一列的索引將會是4(因爲它是從零開始的)。

GridViewProduct.Columns.Insert(4, Quantity); 

我不知道這是否會刪除所有問題,但至少這個錯誤應該去...

+0

@Gerald謝謝..給我同樣的錯誤.. – 2013-05-07 12:06:10

+0

我會調試代碼,並檢查插入語句有多少列...也許別的東西出錯了。 – AGuyCalledGerald 2013-05-07 12:20:42

相關問題