Senior & Expert .Net Developers Discussion Forum by Nyros Technologies

HIRE .Net Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

How to eliminate redundant rows in gridview

 
Post new topic   Reply to topic    Senior & Expert .Net Developers Discussion Forum by Nyros Technologies Index -> Programming with C#
View previous topic :: View next topic  
Author Message
Dileep



Joined: 12 Sep 2007
Posts: 79

PostPosted: Tue Jul 29, 2008 2:55 am    Post subject: How to eliminate redundant rows in gridview Reply with quote

Hi,
In my application i am binding data to gridview, i have redundant data in my database how to eliminate binding redundant rows to Gridview control, can any one give sample code to solve my issue.

Dileep.
Back to top
View user's profile Send private message
venkat



Joined: 21 Aug 2007
Posts: 171

PostPosted: Tue Jul 29, 2008 2:59 am    Post subject: Reply with quote

Hi Dileep,
Can you post your sample code or explain the problem in detail..
Back to top
View user's profile Send private message
Rahul



Joined: 27 Aug 2007
Posts: 138

PostPosted: Tue Jul 29, 2008 3:04 am    Post subject: Reply with quote

Hi Dileep,
We can eliminate redundant data in DataBound event.
try to get values of each row in DataBound event and eliminate redundant rows....

Rahul
Back to top
View user's profile Send private message
Dileep



Joined: 12 Sep 2007
Posts: 79

PostPosted: Tue Jul 29, 2008 3:20 am    Post subject: Reply with quote

Hi venkat,
I am binding table to gridview, table contains two columns State and City. Data in table is
State City
AndhraPradesh Hyderabad
AndhraPradesh Kakinada
AndhraPradesh Vizag
Delhi Delhi
Karnataka Banglore
Karnataka Manglore

When i bind to this table to GridView i want to display the data as
State City
AndhraPradesh Hyderabad
-------- Kakinada
-------- Vizag
Delhi Delhi
Karnataka Banglore
--------- Manglore
Back to top
View user's profile Send private message
venkat



Joined: 21 Aug 2007
Posts: 171

PostPosted: Tue Jul 29, 2008 3:30 am    Post subject: Reply with quote

Hi Dileep,
I am posting sample code relevant to your problem, Write the following code in Gridview DataBound event

for (int i = 0; i < GridView1.Rows.Count - 1; i++)
{
string State = ((Label)GridView1.Rows[i].FindControl("lblStateName")).Text; //here i am getting State name
string City = ((Label)GridView1.Rows[i].FindControl("lblCityName")).Text;
string Next_State = ((Label)GridView1.Rows[i + 1].FindControl("lblRegionName")).Text;
if (State == Next_State) //I am comparing State name with next row state name if both are equal i am placing null value in nextrow state column
{
((Label)GridView1.Rows[i + 1].FindControl("lblStateName")).Text = "";
int k = i+1;
while (k < GridView1.Rows.Count - 1)
{
Next_State = ((Label)GridView1.Rows[k + 1].FindControl("lblStateName")).Text;
if (State == Next_State)
{ ((Label)GridView1.Rows[k+1].FindControl("lblStateName")).Text = "";
}
k++;
}
}
}

It solves your problem..happy coding
Regards,
Venkat.
Back to top
View user's profile Send private message
Dileep



Joined: 12 Sep 2007
Posts: 79

PostPosted: Tue Jul 29, 2008 3:37 am    Post subject: Reply with quote

Thanks Venkat, Keep posting.....
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert .Net Developers Discussion Forum by Nyros Technologies Index -> Programming with C#
Page 1 of 1


 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts Exceptional Manger
1 suraj 26 Thu Sep 02, 2010 8:52 am
Rahul View latest post
No new posts background image for UITableView
0 kumar 31 Wed Sep 01, 2010 10:34 am
kumar View latest post
No new posts Types of Run time exceptions
1 Dheeraj 30 Wed Sep 01, 2010 8:58 am
venkat View latest post
No new posts Access Web Page content in Windows Forms without WebBrowser
3 mouli 258 Wed Sep 01, 2010 7:31 am
rajesh View latest post
No new posts Explain Interlocked Class & Daemon Thread's?
1 mukundh 53 Wed Sep 01, 2010 7:19 am
setty View latest post
No new posts Life Cycle Of Delegate
0 vinay 29 Wed Sep 01, 2010 7:14 am
vinay View latest post
No new posts Accessing methods defined in another page
1 suraj 30 Tue Aug 31, 2010 12:45 pm
Rahul View latest post
No new posts How ASP.Net events are processed?
1 Teena 33 Tue Aug 31, 2010 11:55 am
suraj View latest post
No new posts Universal description discovery and integration
1 Dileep 25 Tue Aug 31, 2010 11:45 am
venkat View latest post
No new posts What is the difference between Shadowing and Overriding ?
1 suraj 35 Tue Aug 31, 2010 11:37 am
Teena View latest post




Hire an expert .Net developer / coder / programmer or development team from India now!!

Other Forums : Ruby on Rails   ::   PHP   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About .Net Experts   |   More