August 14, 2004

Add 2nd Line to Grid Item



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 its not an item or alternating item, get out of here
if (item.ItemType != ListItemType.Item & item.ItemType !=
ListItemType.AlternatingItem)
return;
// we need to access the datarow to get the text, so lets get it
DataRow dataRow = ((DataRowView) item.DataItem).Row;
//now we need to create the new row, add the cell and put in some 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);

// now w need to add it to the table (is always first item in
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.


Posted by sachauncey at 03:02 PM

August 03, 2004

Dot Net Learning Guide

Link ...This SearchWebServices.com guide introduces you to .NET, explains best practices and pitfalls to avoid and provides troubleshooting help and advice. You'll find .NET articles, tutorials, tips, tools, white papers, expert advice and more to pump up your .NET know-how quickly. Drop me an e-mail to let me know what other learning guides you'd like to see on SearchWebServices. Catherine Ketcher, Editor.
TABLE OF CONTENTS
.NET Quick Start
.NET Expert Advice
.NET Migration Tips
.NET White Papers and Chapter Downloads
.NET Code Samples and Tutorials
.NET Tools and Downloads
.NET Online Resources
More Learning Guides
http://searchwebservices.techtarget.com/originalContent/0,289142,sid26_gci995718,00.html?track=NL-130&ad=488175

Posted by sachauncey at 03:39 AM