Good day coders..

I just want to query how could i solve my problem regarding gridview, I want to compare the value of the current row to the previous row of the column, I dont know were should i start.

(ex. id, matnum,soldtoplan
      1,  101,  10101
      2,  102,  10102
      3,  102,  10102
      4,  103,  10103)

if this is my my result table based on my query. and was bind in gridview.
How could i compare the current row to previous row in the current column?

any idea? by the way i used grid_Rowdatabound and bind each column in it..

Member Avatar

LastMitch

any idea? by the way i used grid_Rowdatabound and bind each column in it..

Try this (not tested):

Protected Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView.RowCreated

If e.Row.RowType = DataControlRowType.DataRow Then

if (e.RowType != DataControlRowType.DataRow) return;  
if (e.Row.DataItemIndex ==0)  
{  
  e.Row.Cells[1].id = id.matnum;  
  return;  
}  
var thisRow = e.Row;   
var prevRow = GridView.Rows[e.Row.DataItemIndex-1];  
e.Row.Cells[1].id = (thisRow.Cells[1].Text == prevRow.Cells[1].Text) ? id.matnum : id.soldtoplan;  
}