473,326 Members | 2,128 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,326 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 1994

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: 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:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.