#region Group the GridValue
public DataTable GroupGrid(DataTable dt)
{
DataTable dtA = new DataTable();
dtA = dt.Clone();
string strCurrentValue = string.Empty;
string strPreviousValue = string.Empty;
int m;
int n = 1;
for (m = 0; m < dt.Rows.Count; m++)
{
if (n == 1) // for first value
{
DataRow dr = dtA.NewRow();
dr["Select"] = false;
dr["season"] = dt.Rows[0]["season"].ToString(); //season-> month/monsoon
dr["cluster_no"] = dt.Rows[0]["cluster_no"].ToString();
dr["equation"] = dt.Rows[0]["equation"].ToString();
dtA.Rows.Add(dr);
}
if (n > 1)
{
if (m == 1)
{
object cellValuePrevious = dt.Rows[m]["season"];
strPreviousValue = cellValuePrevious.ToString().Trim();
}
object cellValue = dt.Rows[m]["season"];
strCurrentValue = cellValue.ToString().Trim();
if (strCurrentValue != strPreviousValue) // Now compare the current value with previous value
{
DataRow dr = dtA.NewRow();
dr["Select"] = false;
dr["season"] = dt.Rows[m]["season"].ToString();
dr["cluster_no"] = dt.Rows[m]["cluster_no"].ToString();
dr["equation"] = dt.Rows[m]["equation"].ToString();
dtA.Rows.Add(dr);
strPreviousValue = strCurrentValue;
}
else
{
DataRow dr = dtA.NewRow();
dr["Select"] = false;
dr["season"] = string.Empty;
dr["cluster_no"] = dt.Rows[m]["cluster_no"].ToString();
dr["equation"] = dt.Rows[m]["equation"].ToString();
dtA.Rows.Add(dr);
strPreviousValue = strCurrentValue;
}
}
n++;
}
return dtA;
}
#endregion
public DataTable GroupGrid(DataTable dt)
{
DataTable dtA = new DataTable();
dtA = dt.Clone();
string strCurrentValue = string.Empty;
string strPreviousValue = string.Empty;
int m;
int n = 1;
for (m = 0; m < dt.Rows.Count; m++)
{
if (n == 1) // for first value
{
DataRow dr = dtA.NewRow();
dr["Select"] = false;
dr["season"] = dt.Rows[0]["season"].ToString(); //season-> month/monsoon
dr["cluster_no"] = dt.Rows[0]["cluster_no"].ToString();
dr["equation"] = dt.Rows[0]["equation"].ToString();
dtA.Rows.Add(dr);
}
if (n > 1)
{
if (m == 1)
{
object cellValuePrevious = dt.Rows[m]["season"];
strPreviousValue = cellValuePrevious.ToString().Trim();
}
object cellValue = dt.Rows[m]["season"];
strCurrentValue = cellValue.ToString().Trim();
if (strCurrentValue != strPreviousValue) // Now compare the current value with previous value
{
DataRow dr = dtA.NewRow();
dr["Select"] = false;
dr["season"] = dt.Rows[m]["season"].ToString();
dr["cluster_no"] = dt.Rows[m]["cluster_no"].ToString();
dr["equation"] = dt.Rows[m]["equation"].ToString();
dtA.Rows.Add(dr);
strPreviousValue = strCurrentValue;
}
else
{
DataRow dr = dtA.NewRow();
dr["Select"] = false;
dr["season"] = string.Empty;
dr["cluster_no"] = dt.Rows[m]["cluster_no"].ToString();
dr["equation"] = dt.Rows[m]["equation"].ToString();
dtA.Rows.Add(dr);
strPreviousValue = strCurrentValue;
}
}
n++;
}
return dtA;
}
#endregion
No comments:
Post a Comment