2012-12-13 24 views
2

我想在Gridview頁面中插入一個控件。控制顯示成功,但它可以在前面的控制下分配,如圖所示。在Gridview頁面中插入自定義按鈕

enter image description here

我用下面的代碼添加。

if (e.Row.RowType == DataControlRowType.Pager) 
{ 
    e.Row.Cells[0].Controls.Add(ImageButton1); 
} 

我想要的是分配保存答案按鈕旁邊的上一個按鈕,而不是下面。任何幫助嗎?

+0

不,我沒有一個模板。我只有EnablePaging True – user1292656

回答

2
if (e.Row.RowType == DataControlRowType.Pager) 
{ 
    Table pagerTable = (e.Row.Cells[0].Controls[0] as Table); 
    TableRow row = new TableRow(); 
    row = pagerTable.Rows[0]; 
    TableCell cell1 = new TableCell(); 
    cell1.Controls.Add(ImageButton1); 

    row.Cells.AddAt(1,cell1); 
} 
0

也許你可以在你的GridView添加新頁面風格:

<PagerStyle Width="100%" /> 

你爲什麼不創建一個內部的按鈕pagertemplate? 您將更容易定義每個按鈕的位置。

<asp:gridview id="CustomersGridView" 
     datasourceid="CustomersSource" 
     autogeneratecolumns="false" 
     emptydatatext="No data available." 
     allowpaging="true" 
     runat="server"> 
... 
     <pagerstyle Width="100%"/> 

     </asp:gridview> 
+0

沒有單元格1 :) – user1292656

+0

我該怎麼做? – user1292656

+0

再次不起作用 – user1292656