| View previous topic :: View next topic |
| Author |
Message |
Dileep
Joined: 12 Sep 2007 Posts: 79
|
Posted: Tue Jul 29, 2008 2:55 am Post subject: How to eliminate redundant rows in gridview |
|
|
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 |
|
 |
venkat
Joined: 21 Aug 2007 Posts: 171
|
Posted: Tue Jul 29, 2008 2:59 am Post subject: |
|
|
Hi Dileep,
Can you post your sample code or explain the problem in detail.. |
|
| Back to top |
|
 |
Rahul
Joined: 27 Aug 2007 Posts: 138
|
Posted: Tue Jul 29, 2008 3:04 am Post subject: |
|
|
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 |
|
 |
Dileep
Joined: 12 Sep 2007 Posts: 79
|
Posted: Tue Jul 29, 2008 3:20 am Post subject: |
|
|
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 |
|
 |
venkat
Joined: 21 Aug 2007 Posts: 171
|
Posted: Tue Jul 29, 2008 3:30 am Post subject: |
|
|
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 |
|
 |
Dileep
Joined: 12 Sep 2007 Posts: 79
|
Posted: Tue Jul 29, 2008 3:37 am Post subject: |
|
|
| Thanks Venkat, Keep posting..... |
|
| Back to top |
|
 |
|