I´m using this code to check duplicate data in a gridview :
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int rowCount = rowCount = GridView1.Rows.Count;
if (e.Row.RowIndex > 1)
{
//set reference to the row index and the current value
int intC = e.Row.RowIndex;
string lookfor = e.Row.Cells[0].Text;
//Label1.Text = lookfor.ToString(); ;
//now loop back through checking previous entries for matches
do
{
GridViewRow Gprev = GridView1.Rows[intC - 1];
if (Gprev.Cells[0].Text.Equals(e.Row.Cells[0].Text))
{
e.Row.Cells[0].Text = string.Empty;
}
intC = intC - 1;
} while (intC > 0);
}
}
Is there a way to hide this entry instead of showing the duplicate row without text ?
Mojorz
Member
3 Points
22 Posts
Hide Duplicate Results in Gridview
Nov 15, 2012 12:17 AM|LINK
Hi
I´m using this code to check duplicate data in a gridview :
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { int rowCount = rowCount = GridView1.Rows.Count; if (e.Row.RowIndex > 1) { //set reference to the row index and the current value int intC = e.Row.RowIndex; string lookfor = e.Row.Cells[0].Text; //Label1.Text = lookfor.ToString(); ; //now loop back through checking previous entries for matches do { GridViewRow Gprev = GridView1.Rows[intC - 1]; if (Gprev.Cells[0].Text.Equals(e.Row.Cells[0].Text)) { e.Row.Cells[0].Text = string.Empty; } intC = intC - 1; } while (intC > 0); } }oned_gk
All-Star
30991 Points
6344 Posts
Re: Hide Duplicate Results in Gridview
Nov 15, 2012 12:29 AM|LINK
Store e.Row.Cells[0].Text to viewstate or hiddenfield.value
Viewstate("findduplicate")=e.Row.Cells[0].Text or Hiddenfield1.value=e.Row.Cells[0].Text
compare the value. If same then set text to empty, if not same set viewstate to new cell text
e.Row.Cells[0].Text=""
Mojorz
Member
3 Points
22 Posts
Re: Hide Duplicate Results in Gridview
Nov 15, 2012 12:42 AM|LINK
Hi
Is there a way of hiding the duplicated cell from the gridview template .
Thanks for your time
oned_gk
All-Star
30991 Points
6344 Posts
Re: Hide Duplicate Results in Gridview
Nov 15, 2012 12:58 AM|LINK
try use
e.Row.Cells[0].Controls[0].Text
Paul Linton
Star
13403 Points
2531 Posts
Re: Hide Duplicate Results in Gridview
Nov 15, 2012 03:13 AM|LINK
"If it hurts when you do that, then stop doing that"
Don't put the duplicate rows in the grid in the first place. It should be easier to fix the datasource so that it only produces the results you want.