473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 993

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John Ruiz | last post by:
Greetings, I originally posted this to microsoft.public.dotnet.framework.aspnet.datagridcontrol two weeks ago, but no one was able to answer. I am unable to dynamically add columns to a...
1
by: Mark | last post by:
Hello, I have a need to add a button column to a datagtrid, below is my code and although it does not produce an error, it also does not work, any help? I'm hoping that I can capture the button...
4
by: bill | last post by:
Can I add multiple datagrid controls dynamically at runtime? I want to break up my dataset into separate datagrids, so I can insert a "<p style="page-break-before: always"> tag between them. ...
3
by: Matt | last post by:
Hi there, I have a datagrid that allows the user to add new row to it. In these rows I want to add a dropdownlist. How do I add a dropdownlist programatically to a datagrid? thanks, Matt
3
by: david | last post by:
I have posted my question before. It seems that I can not find the solution. The question: I have datasource, say, ds which is bounded to a datagrid, dg. Assume that ds have 5 columns,...
0
by: news.zen.co.uk | last post by:
Hi Guys, Using VB .NET 2003 and ASP1.1, I have a Datagrid embedded in an ASP page. In the processing of the ItemDataBound event I dynamically create a new Datagrid control within the Cell of the...
4
by: sydney.luu | last post by:
Hello, I would greatly appreciate if someone can show me how to dynamically build a Repeater with unknown number of columns at design time. I have looked various threads in this newsgroup,...
0
by: herman404 | last post by:
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...
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
4
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.