db grid display of duplicates

G

Guest

I have a question about how to display (or not to display) a column value that is same as the previous row.

For eg.
I have data in the database like this,

City Name Telephone
New York Abc 123434432
New York Xyz 321321312
Philly Raja 656567657
Philly Marice 343243434


I want to display this in a datagrid in such way that the output would be
City Name Telephone
New York Abc 123434432
Xyz 321321312
Philly Raja 656567657
Philly Marice 343243434
(note: for the row "Xyz" the city is 'blank', becasue it is same as the prevous row)

Hope you can help me do this.

Thanks in advance
Raja
 
E

Ersin Gençtürk

hi raja,

hi raja,

you may user datagrid itemcreated event.

if you are using a datatable you can get datatable row number by :

e.item.datasetindex

so if your datasource is DataTable MyTable;

then MyTable[e.Item.DataSetIndex] would return you the row that the grid is
rendering now.

and after you can check the value with the previos value with the value in
the MyTable[e.Item.DataSetIndex-1]

if they are same , you can hide text displayed.

for this ofcourse you may use a label control in a template to show city
column and after you can use a syntax like this :

((Label)e.Item.FindControl("lblCityName")).Visible=false;

regards,
ersin



Raja said:
I have a question about how to display (or not to display) a column value
that is same as the previous row.
 
J

Joyjit Mukherjee

Hi,

You can set the autogeneratecolumns property of the grid to false, then
create a manual itemtemplete for each columns. Then, for each itemtemplate,
mask it with your own serverside function as follows:-

<itemtemplate>
<%# checkcity(Container.DataItem("City"))%>
</itemtemplate>

in the codebehind, write a function checkcity as follows:-

Public Class Mypage

Public oldcity as string = ""
....
....

Private Function checkcity(Byval city as string)
If Len(oldcity) = 0 Then

oldcity = city
checkcity = city

Else
If oldcity.COmpare(city, oldcity) = 0 Then
oldcity = city
checkcity=""
Else
oldcity = city
checkcity=city
End IF
End If
End Function

End Class

Regards
Joyjit

Raja said:
I have a question about how to display (or not to display) a column value
that is same as the previous row.
 

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

Top