I'm trying to add a custom row for each Item and Alternating
Item that is added to my datagrid. The idea is for each row created,
to create another row beneath it, so I can have one cell that spans
all the columns to display a lot of text.
Heres the code i'm using for the OnItemCreated event:
private void dgAlerts_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataGridItem item = e.Item;
if (item.ItemType != ListItemType.Item & item.ItemType !=
ListItemType.AlternatingItem)
return;
DataRow dataRow = ((DataRowView) item.DataItem).Row;
text.
DataGridItem oNewItem = new
DataGridItem(item.ItemIndex,item.DataSetIndex,item.ItemType);
TableCell oNewCell = new TableCell();
oNewItem.Cells.Add( oNewCell);
oNewCell.ColumnSpan = item.Cells.Count;
Label oFullText = new Label();
oFullText.Text = (string)
dataRow[(int)enumAlertDataGridColumns.Details];
oNewCell.Controls.Add(oFullText);
datagrid controls) and we're done!
dgAlerts.Controls[0].Controls.Add(oNewItem);
}
If you change the event from ItemCreated to ItemDataBound
and use the same code, you will get the custom row below instead of
above your items.
<asp:DataGrid id="dgAlerts" OnItemDataBound="dgAlerts_ItemDataBound" .... />
and change the name of the private void, to dgAlerts_
ItemDataBound instead of ItemCreated.The created event has
not created your item yet, so when you append to the Controls[0]
you get it before the DataBound one. So when you change
it to the DataBound one, the Item is already created and you can
then append the new row AFTER the DataBound one.
|