如何将gridview传递给另一个

如何将gridview传递给另一个

本文介绍了如何将gridview传递给另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);每次我从dropdownlist cmd.CommandText中选择时都会不断变化,我想要的是将第一行的值传递给另一个`gridview1,第二次将它循环到gridview1以下的行。到目前为止,我正在使用它:


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:

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();





但是这个GridView1只显示第一次循环中的行值。 3行中的相同值。我需要的是在GridView1中每行都有不同的行值,我从dtoutput.Rows.Add(newrowPassCount)得到;在每次从命令中选择。我只是没有得到正确的逻辑。请指南?我被困了一个星期..



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..

推荐答案

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

foreach (var tempRow in dtoutput.Rows)
{
     tempdatatable.NewRow();
     tempdatatable.Rows.Add(tempRow[0], tempRow[1]);
}


这篇关于如何将gridview传递给另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 11:12