Button not appearing in DataGrid column



I have been attemting to add a button to the 4th column of a DataGrid
but each time the web page is displayed, the button is not there. When
defining the 4th column initially, I have not placed any value within
it and have added the button after databindinding the datagrid to a
dataset with 4 columns (including the empty 4th column). The resultant
HTML for the DataGrid is below:

<div id="PegasusDataGrid" name="PegasusDataGrid" style="Z-INDEX: 107;
LEFT: 208px; POSITION: absolute; TOP: 200px; ">
<div style="OVERFLOW-Y: auto">
<table class="HeaderStyle" bordercolor="DarkGray" rules="all"
collapse:collapse;background-color:#CC0000;" cellpadding="2"
cellspacing="0" width="673">
<tr width="673">
<td width="140px"><font color="White"><b>Database</b></font></td>
<td width="150px"><font color="White"><b>Type</b></font></td>
<td width="300px"><font color="White"><b>Table Name</b></font></
<td width="100px"><font color="White"><b>Select</b></font></td>
<div style="OVERFLOW-Y: auto; HEIGHT: 360px; WIDTH: 690px"
style="OVERFLOW-Y: auto; HEIGHT: 360px; WIDTH: 690px; OVERFLOW-Y:
<table ID="PegasusDataGridTable" bordercolor="DarkGray"
rules="all" style="TABLE-LAYOUT: fixed; BORDER-STYLE: Solid; BORDER-
COLLAPSE: collapse" cellpadding="2" cellspacing="0" width="673">
<tr ID="PegasusDataGrid_tbl0_sub0_row0" class="NormalStyle">
<td width="140px">DCRS</td>
<td width="150px">Control</td>
<td width="300px">TCPR009A_CONTROL</td>
<td width="100px">&nbsp;</td>
<tr ID="PegasusDataGrid_tbl0_sub0_row1" class="NormalStyle"
<tr ID="PegasusDataGrid_tbl0_sub0_row2" class="NormalStyle">

My code to add the button to the 4th column of every row is below:

for (int iRow=0; iRow<PegasusReportsGrid.Items.Count; iRow++)
string strDatabaseName =
string strType = PegasusReportsGrid.Items[iRow].Cells[1].Text;
string strTableName =

System.Web.UI.WebControls.ImageButton bSelect = new
bSelect.ID = "SelectButton-"+strDatabaseName+"-"+strType
bSelect.Command += new CommandEventHandler(UpdateSelected);
bSelect.ImageUrl = "images/button-select-up.jpg";
//bSelect.Attributes["onclick"] =
bSelect.Visible = true;

It is definitley stepping through this code OK and processes the logic
for each row found (in this case, 3 rows). I have tried this with and
without the databind (commented out above).

It looks ok to me and, indeed, the code does not fail, but the button
is not added. Any ideas?

Just for extra help, the initial code to build the grid from the data
is below (reformattedTableList has 4 columns, the 4th being called

PegasusReportsGrid.FixedHeader = true;
PegasusReportsGrid.TableLayoutFixed = true;
PegasusReportsGrid.ID = "ReportsTable";
PegasusReportsGrid.HeaderStyle.CssClass = "HeaderStyle";
PegasusReportsGrid.ItemStyle.CssClass = "NormalStyle";
PegasusReportsGrid.AlternatingItemStyle.CssClass = "NormalStyle";
PegasusReportsGrid.AlternatingItemStyle.BackColor =
//PegasusReportsGrid.HeaderStyle.BackColor = Color.Red;
PegasusReportsGrid.HeaderStyle.Font.Bold = true;
PegasusReportsGrid.HeaderStyle.BorderColor = Color.DarkGray;
PegasusReportsGrid.BorderColor = Color.DarkGray;
PegasusReportsGrid.Width = Unit.Pixel(totalWidth);
PegasusReportsGrid.Height = Unit.Pixel(360);
PegasusReportsGrid.CellPadding = 2;
PegasusReportsGrid.CellSpacing = 0;

PegasusReportsGrid.GridLines = GridLines.Both;
PegasusReportsGrid.HeaderStyle.BorderStyle =
PegasusReportsGrid.BorderStyle =

PegasusReportsGrid.DataSource =

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