在弄清楚如何将 ButtonColumn 添加到 DataTable(或者,可以说是 DataGrid)时遇到奇怪的问题。我想做的就是能够使用数据表中的数据来告诉按钮在单击时执行某些操作,但我似乎失败了。
谷歌搜索没有显示任何立即有用的东西,因为它们都在使用 ItemTemplates。
//dt.Columns.Add("Ajax Link", typeof(Literal));
ButtonColumn newButtonColumn = new ButtonColumn();
newButtonColumn.HeaderText = "Asp.Net Link";
dt.Columns.Add(); // Doesn't want newButtonColumn.
for (int i = 0; i < dt.Rows.Count; i++)
{
/*
Literal newAjaxLink = new Literal();
newAjaxLink.Text = "Test";//"<button type=\"button\" onclick=\"AjaxButton_onClick(" + dt.Rows[i]["UserInfoID"].ToString() + "); StoreUserInfoID(" + dt.Rows[i]["UserInfoID"].ToString() + "); ShowDiv();\">Ajax Link</button>";
dt.Rows[i]["Ajax Link"] = newAjaxLink; // @todo: HTML button that triggers an AJAX call for load the proper data into the fields. Also to make the DIV visible.
*/
Button newButton = new Button();
newButton.ID = dt.Rows[i]["UserInfoID"].ToString();
newButton.Text = "Asp.Net Link";
newButton.Click += new EventHandler(Button_Link_Click);
dt.Rows[i]["Asp.Net Link"] = newButton; //@todo: Just a button to open a new window with the proper ID.
}
有任何想法吗?