Button not appearing in DataGrid column


S

stainless

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"
style="table-layout:fixed;border-style:Solid;border-
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>
<td width="100px"><font color="White"><b>Select</b></font></td>
</tr>
</table>
<div style="OVERFLOW-Y: auto; HEIGHT: 360px; WIDTH: 690px"
style="OVERFLOW-Y: auto; HEIGHT: 360px; WIDTH: 690px; OVERFLOW-Y:
auto">
<table ID="PegasusDataGridTable" bordercolor="DarkGray"
rules="all" style="TABLE-LAYOUT: fixed; BORDER-STYLE: Solid; BORDER-
COLLAPSE: collapse" cellpadding="2" cellspacing="0" width="673">
<tbody>
<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>
<tr ID="PegasusDataGrid_tbl0_sub0_row1" class="NormalStyle"
style="background-color:WhiteSmoke;border-style:NotSet;">
<td>DWOP</td>
<td>Control</td>
<td>TWO036A_CONTROL</td>
<td>&nbsp;</td>
</tr>
<tr ID="PegasusDataGrid_tbl0_sub0_row2" class="NormalStyle">
<td>DD2D</td>
<td>Control</td>
<td>TD2D021A_CONTROL</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>


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 =
PegasusReportsGrid.Items[iRow].Cells[0].Text;
string strType = PegasusReportsGrid.Items[iRow].Cells[1].Text;
string strTableName =
PegasusReportsGrid.Items[iRow].Cells[2].Text;

System.Web.UI.WebControls.ImageButton bSelect = new
System.Web.UI.WebControls.ImageButton();
bSelect.ID = "SelectButton-"+strDatabaseName+"-"+strType
+"-"+strTableName;
bSelect.Command += new CommandEventHandler(UpdateSelected);
bSelect.ImageUrl = "images/button-select-up.jpg";
//bSelect.Attributes["onclick"] =
"javascript:ShowHide('DataGridLabel','hidden');";
bSelect.Visible = true;
//bSelect.DataBind();
PegasusReportsGrid.Items[iRow].Cells[3].Controls.Add(bSelect);
}


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
"Select"):

PegasusReportsGrid.FixedHeader = true;
PegasusReportsGrid.TableLayoutFixed = true;
PegasusReportsGrid.ID = "ReportsTable";
PegasusReportsGrid.HeaderStyle.CssClass = "HeaderStyle";
PegasusReportsGrid.ItemStyle.CssClass = "NormalStyle";
PegasusReportsGrid.AlternatingItemStyle.CssClass = "NormalStyle";
PegasusReportsGrid.AlternatingItemStyle.BackColor =
Color.WhiteSmoke;
//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 =
System.Web.UI.WebControls.BorderStyle.Solid;
PegasusReportsGrid.BorderStyle =
System.Web.UI.WebControls.BorderStyle.Solid;

PegasusReportsGrid.DataSource =
reformattedTableList.Tables[0].DefaultView;
PegasusReportsGrid.DataBind();
 
Ad

Advertisements


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

Top