我正在尝试在 Gridview 寻呼机中插入一个控件。如您在图片中看到的,该控件成功显示,但它在先前的控件下分配它。
我正在添加以下代码。
if (e.Row.RowType == DataControlRowType.Pager)
{
e.Row.Cells[0].Controls.Add(ImageButton1);
}
我想要的是在上一个按钮旁边而不是下面分配保存答案按钮。有什么帮助吗?
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);
}
也许您可以在 gridview 中添加寻呼机样式:
<PagerStyle Width="100%" />
为什么不创建一个带有按钮的页面模板?您可以更轻松地定义每个按钮的位置。
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="false"
emptydatatext="No data available."
allowpaging="true"
runat="server">
...
<pagerstyle Width="100%"/>
</asp:gridview>