Add New Datagrid Row Dynamically - ItemCreated

P

PD

I'm trying to add a new row to a datagrid object. See code below:

Private Sub dgImageList_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgImageList.ItemCreated

If e.Item.ItemType = ListItemType.Item Then

Dim tc As TableCell = New TableCell
Dim strFundTypeCd As String = "Testing"

tc.Controls.Add(New LiteralControl(strFundTypeCd))
tc.ColumnSpan = 6
tc.ID = "tc11" & e.Item.ItemIndex

Dim di As DataGridItem = New DataGridItem(e.Item.ItemIndex + 1, 0,
ListItemType.Item)
di.BorderStyle = BorderStyle.Groove
di.Cells.Add(tc)

Dim tb As Table = dgImageList.Controls(0)
tb.Rows.Add(di)
End If

When I view the source, I notice there is a <tr> row object that is
added to the grid, but no <td> cell is in it. Hence, there is no data
displayed and the row is empty. Here is the HTML source of the page
showing the <tr> row.

<tr valign="Middle" style="border-color:Black;border-style:Groove;">
</tr>

As you can see, no <td> tag.

The grid has already been data bound at this point, so I'm not sure if
that has something to do with it. I have tried placing the code in the
ItemDataBound event of the grid as well. Same results.

Adding the row to the dataset is not an option as well as I need to
build the grid dynamically.

Any suggestions would be greatly appreciated.

Patrick
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top