2
A
回答
3
protected void Page_Load(object sender, EventArgs e)
{
DataGrid dg = new DataGrid();
dg.GridLines = GridLines.Both;
dg.Columns.Add(new ButtonColumn {
CommandName = "add",
HeaderText = "Event Details",
Text = "Details",
ButtonType = ButtonColumnType.PushButton
});
dg.DataSource = getDataTable();
dg.DataBind();
dg.ItemCommand += new DataGridCommandEventHandler(dg_ItemCommand);
pnlMain.Controls.Add(dg);
}
protected void dg_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "add")
{
throw new Exception("add it!");
}
}
protected DataTable getDataTable()
{
// returns your data table
}
0
MSDN網站上的這篇文章清楚地說明了如何去adding a button into a datagrid。而不是使用按鈕的單擊事件,您將使用DataGrid的命令事件。每個按鈕都將傳遞您要設置的特定命令參數。
本文顯示how to use the command event with buttons。在這裏你使用CommandArguments和CommandNames。
0
這裏就是我創建數據網格:
System.Web.UI.WebControls.DataGrid Datagridtest =新System.Web.UI.WebControls.DataGrid();
Datagridtest.Width = 600;
Datagridtest.GridLines = GridLines.Both;
Datagridtest.CellPadding = 1;
ButtonColumn bc = new ButtonColumn();
bc.CommandName = "add";
bc.HeaderText = "Event Details";
bc.Text = "Details";
bc.ButtonType = System.Web.UI.WebControls.ButtonColumnType.PushButton;
Datagridtest.Columns.Add(bc);
PlaceHolder1.Controls.Add(Datagridtest);
Datagridtest.DataSource = dt;
Datagridtest.DataBind();
這裏是我試圖使用事件:
保護無效Datagridtest_ItemCommand(對象源,DataGridCommandEventArgs E) { .... }
思想,可以幫助因爲我似乎無法捕捉到這個事件。
相關問題
- 1. ASP.NET添加html按鈕單擊事件
- 2. 單擊事件爲HTML動態按鈕
- 3. 如何在按鈕單擊事件(C sharp ASP.NET)上創建動態按鈕?
- 4. 訪問按鈕上的Datagrid內的複選框單擊Asp.net
- 5. 在asp.net中按鈕點擊動態添加控件mvc
- 6. 添加按鈕在EXTjs中動態點擊事件4
- 7. Click事件WPF DataGrid的按鈕列添加在PowerShell中
- 8. Programaticlly添加按鈕單擊事件
- 9. 將onclick事件添加到動態添加的單選按鈕
- 10. 動態地添加控件[e.g按鈕]:如何添加事件和訪問
- 11. 添加事件動態創建按鈕
- 12. 添加鏈接按鈕事件動態
- 13. 動態創建添加表單點擊添加按鈕在angularjs
- 14. c#添加動態點擊事件
- 15. DataGrid中的靜態DropDownList在按鈕單擊事件後返回錯誤的選定值C#ASP.NET
- 16. .Net Compact Framework - 爲按鈕單擊事件添加振動
- 17. 如何在wpf中的datagrid中動態添加按鈕?
- 18. ASP.net在Button按鈕上動態添加控件。回覆問題
- 19. 分配點擊事件來動態添加按鈕
- 20. 動態添加ASP.Net按鈕無法調用Click或CommandArgument事件
- 21. C#動態添加按鈕,並與發送事件的args它
- 22. 如何在TableRow中動態創建按鈕單擊事件?
- 23. 添加點擊事件單選按鈕Ext.form.Radio在Ext JS中
- 24. 在c#中動態分配按鈕事件asp.net
- 25. 添加圖像/按鈕單擊事件處理程序動態在C#中的Silverlight
- 26. ASP.net C#按鈕單擊
- 27. 如何在單擊事件上的按鈕上添加聲音?
- 28. 簡單的動態按鈕列表asp.net
- 29. 添加點擊事件動態添加按鈕到劍道窗口內容
- 30. 在Flex中動態添加列到datagrid
上有標題錯字:dynamitcally->動態 – hayalci 2008-09-29 17:45:17