By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,426 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,426 IT Pros & Developers. It's quick & easy.

db grid display of duplicates

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <Ra**@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
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

Nov 18 '05 #2

P: n/a
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" <Ra**@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.