Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
cmd.CommandText = "select * from " + csv + " WHERE Station LIKE '%' + @param1 + '%'";

foreach (DataRow row in dt.Rows)

{
    lstData.Add(new Tablelist() 
    {
        FileName = csv.Replace(".csv", "").Replace(".CSV", ""), 
    Process = row["Process"] + "", 
    Station = row["Station"] + "", 
    Event = row["Event"] + "", 
    Status = row["Status"] + "" 
});
}

//Get File Name from listdata
var columnNames = lstData.Select(k => k.FileName).Distinct();

//Add a new column with the file name that have selected from above
foreach (string columnName in columnNames)
{
    dtoutput.Columns.Add(columnName, typeof(string));
}

DataRow newrowPassCount = dtoutput.NewRow();
DataRow newrowReworkCount = dtoutput.NewRow();
DataRow newrowfortime = dtoutput.NewRow();

//Assign previous value
int pprevcount = 0;
int rprevcount = 0;
int Totalppmcount = 0;

//Count the pass and the Reworkfrom the csv files that selected
foreach (string columnName in columnNames)
{

    int pcount = lstData.Where(k => k.FileName == columnName).Count(k => k.Status.Trim() == "PASS");
    int rcount = lstData.Where(k => k.FileName == columnName).Count(k => k.Status.Trim() == "REWORK");
    newrowfortime[columnName] = columnName;
    int Passcount = pcount - pprevcount;
}

dtoutput.Rows.Add(newrowPassCount);
dtoutput.Rows.Add(newrowReworkCount);

dtoutput.Rows.Add(newrowPassCount); will keep changing everytime I select from dropdownlist cmd.CommandText, what I want is to pass the row values from the firs time it loops to another `gridview1, and second time it loops to gridview1 the following rows. So far I'm using this:
C#
foreach (string columnName in columnNames)
{
    tempdatatable.Columns.Add(columnName, typeof(string));
}
int j = 1;

var tempRow = dtoutput.Rows[j];

int rowIndex = 2;
for (int i = dtoutput.Rows.Count - 1; i >= 0; i--)
{

    if (i == rowIndex)
    {

        tempdatatable.NewRow();
        tempdatatable.Rows.Add(tempRow[0], tempRow[1]);
    }
    rowIndex--;


}

GridView1.DataSource = tempdatatable;
GridView1.DataBind();


But this GridView1 only show the row values in first time loops. Same values in 3 rows. What I need is in GridView1 each rows different row values which I get from dtoutput.Rows.Add(newrowPassCount); in everytime selected from command. I just don't get the right logic. Please Guide ? I have been stuck for one week..
Posted
v2

1 solution

Look at my comments below
C#
foreach (string columnName in columnNames)
{
    tempdatatable.Columns.Add(columnName, typeof(string));
}
int j = 1;

//Right here you are putting in tempRow row j ( = 1)
var tempRow = dtoutput.Rows[j];

int rowIndex = 2;
for (int i = dtoutput.Rows.Count - 1; i >= 0; i--)
{
    if (i == rowIndex)
    {
        tempdatatable.NewRow();
// Right here you are using the same tempRow values for every row.
        tempdatatable.Rows.Add(tempRow[0], tempRow[1]);
    }

    rowIndex--;
}


Try this instead

C#
foreach (var tempRow in dtoutput.Rows)
{
     tempdatatable.NewRow();
     tempdatatable.Rows.Add(tempRow[0], tempRow[1]);
}
 
Share this answer
 
Comments
acing wei 16-Jan-14 18:43pm    
But there is a problem here everytime when the page is being refresh , the previous row values in temptable will disappear, what should I do to retain the old row values in temptable ?
bowlturner 17-Jan-14 10:25am    
you can put them in the session to keep them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900