Dynamically add button column to DataGrid

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top