H
herman404
Hi everyone, I'm trying to dynamically add 3 button columns to a
DataGrid object that I have on an ASP.net webpage, but I don't see any
documentation on how to do it. I've seen plenty of examples on how to
add regular columns, but how do you declare a button column? My code is
posted below, I have a placeholder on a webform, and the datagrid will
be added on the placeholder once it is initalised. Thanks!
System.Web.UI.WebControls.Label lblNoRecords = new
System.Web.UI.WebControls.Label();
clsResults objResults = new clsResults();
objResults.SourceWebPage = this;
objResults.SQLString = sSQLString;
// Set datagrid reference to returned results
this.dgTable = objResults.DataGrid;
// Add button columns to datagrid
DataColumn editButton = ???
DataColumn updateButton = ???
DataColumn cancelButton = ???
// Add event handlers
this.dgTable.EditCommand += new
DataGridCommandEventHandler(dgTable_EditCommand);
this.dgTable.CancelCommand += new
DataGridCommandEventHandler(dgTable_CancelCommand);
this.dgTable.UpdateCommand += new
DataGridCommandEventHandler(dgTable_UpdateCommand);
// Add datagrid to webform
//PlaceHolder1.Controls.Add(objResults.DataGrid);
this.PlaceHolder1.Controls.Add(this.dgTable);
if (objResults.RecordsRetrieved == 0)
{
lblNoRecords.Text = "No records retrieved from database";
lblNoRecords.CssClass = "norecordsText";
PlaceHolder1.Controls.Add(lblNoRecords);
}
objResults = null;
DataGrid object that I have on an ASP.net webpage, but I don't see any
documentation on how to do it. I've seen plenty of examples on how to
add regular columns, but how do you declare a button column? My code is
posted below, I have a placeholder on a webform, and the datagrid will
be added on the placeholder once it is initalised. Thanks!
System.Web.UI.WebControls.Label lblNoRecords = new
System.Web.UI.WebControls.Label();
clsResults objResults = new clsResults();
objResults.SourceWebPage = this;
objResults.SQLString = sSQLString;
// Set datagrid reference to returned results
this.dgTable = objResults.DataGrid;
// Add button columns to datagrid
DataColumn editButton = ???
DataColumn updateButton = ???
DataColumn cancelButton = ???
// Add event handlers
this.dgTable.EditCommand += new
DataGridCommandEventHandler(dgTable_EditCommand);
this.dgTable.CancelCommand += new
DataGridCommandEventHandler(dgTable_CancelCommand);
this.dgTable.UpdateCommand += new
DataGridCommandEventHandler(dgTable_UpdateCommand);
// Add datagrid to webform
//PlaceHolder1.Controls.Add(objResults.DataGrid);
this.PlaceHolder1.Controls.Add(this.dgTable);
if (objResults.RecordsRetrieved == 0)
{
lblNoRecords.Text = "No records retrieved from database";
lblNoRecords.CssClass = "norecordsText";
PlaceHolder1.Controls.Add(lblNoRecords);
}
objResults = null;