How to mark first occurence of value in a datagrid?

  • Thread starter Thread starter John Martin
  • Start date Start date
J

John Martin

This should be an easy match, but I'm lost. I want to perform a kind
of grouping of the data in a datagrid object, so that only the first
occurrence of a value in column one is visible. The following equal
rows should be blanked in column one, se example:

Col.one Col.two Col.three
A Data1 DataA1
Data2 DataA2
Data3 DataA3
B Data1 DataB1
Data2 DataB2

etc...

I'm trying to do this in the ItemCreated event, but I'm not able to
compare the current row with the previous. Or store the previous value
in some variable.. Please help, it's getting late!

Regards,
John Martin
 
Hi,

Declare Dummy as string at Page level. Comapre each columns values with
Dummy. If same then Set cell value as "" else set the Dummy variable with
Cell value.

Hope code below will help.

Thanks,

SSW
MCSD, MCAD, OCA
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----

Code Begin
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----
private string Dummy;//Class level variable
private void dgURGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int i = 0;
if (e.Item.ItemType.ToString() !="Header")
{
if(e.Item.DataItem !=null)
{
DataGridItem di = new DataGridItem(e.Item.ItemIndex,
e.Item.DataSetIndex, ListItemType.Separator);
if(Dummy!=e.Item.Cells.Text)
Dummy = e.Item.Cells.Text;
else
e.Item.Cells.Text = "";
}
}
}
----------------------------------------------------------------------------
 
Back
Top