469,160 Members | 2,063 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,160 developers. It's quick & easy.

Dynamically add button column to DataGrid

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;

Jun 12 '06 #1
0 1584

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by John Ruiz | last post: by
4 posts views Thread by bill | last post: by
3 posts views Thread by david | last post: by
4 posts views Thread by sydney.luu | last post: by
reply views Thread by herman404 | last post: by
4 posts views Thread by Craig Buchanan | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.