Blank Row When Adding to DataGrid

J

Jason

I'm working on an aspx page that will display the contents of a
shopping cart then show the subtotal, any discounts, and the final
total after that. I'm pulling the contents of the shopping cart from
a database with the following code:

MyDataGrid.DataSource = cart.GetItems(cartId); // returns
// a SqlDataReader
MyDataGrid.DataBind();

After this, I would like to add three rows to the end of the DataGrid
containing the subtotal, discount, and total. To get started, I
simply want to add a single row to the end with the word "Test" in it.
I have tried the following code:

DataGridItem gridItem = new DataGridItem(0, 0, ListItemType.Header);
TableCell cell = new TableCell();
cell.ColumnSpan = 5;
cell.Text = "Test";
gridItem.Cells.Add(cell);
MyDataGrid.Controls[0].Controls.Add(gridItem);

I have tried putting this in the OnItemCreated and OnDataBinding
events and in both cases got the same result - an emtpy row appended
to the end of the DataGrid. When I view the source for the page, just
before the end of the table that is created, there is a <tr> </tr> set
of tags with nothing inside them.

If anyone can help me figure out what is going on here and how to get
this to work, I would greatly appreciate it. I apologize in advance
if this is a question that gets asked here all the time, but I've
spent all morning searching for an answer with no luck. Thank you.
 

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

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top