why does not it return all the rows in the gridView?

0

Testing this method when in a gridview with checkbox if 1 checkbox is selected, then a modal with that selection is displayed in another gridview, and if 2 or more checkboxes are selected in the first gridview, the selected rows in another gridview are shown. So far so good, but now I need to convert each of the gridview rows in xml to pass it to a webservice, that's the main idea, but the label does not show me more than 1 row, it does not show me 2 or 3 or more rows .

Code:

foreach (GridViewRow row in gwPreview.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
                if (chkRow.Checked)
                {
                    string ciudad = (row.Cells[1].FindControl("lblCONSULTA") as Label).Text;
                    string data = row.Cells[2].Text;
                    string remision = row.Cells[3].Text;
                    string fechaEmision = row.Cells[4].Text;
                    dt.Rows.Add(ciudad, data, remision, fechaEmision);

                    lblHelper1.Text = "<code>" + " | " + ciudad + " | " + data + " | " + remision + " | " + fechaEmision + "</code>" 
                }
            }
        }
        gvSelected.DataSource = dt;
        gvSelected.DataBind();

Gridview1

ciudad | data | remision | fechaemision | checkbox 
----------------------------------------|---------
city1  |  01  |    2448  | 20171010     |   X 
city2  |  02  |    2447  | 20171021     |   X
city3  |  03  |    2457  | 20170928     |

GridviewPreview

ciudad | data | remision | fechaemision | 
----------------------------------------|
city1  |  01  |    2448  | 20171010     | 
city2  |  02  |    2447  | 20171021     |

lblHelper1 obtained

city1  | 01 | 2448 | 20171010

lblHelper1 Expected result

city1  | 01 | 2448 | 20171010 | city2 | 02 | 2447 | 20171021
    
asked by Vulpex 30.10.2017 в 13:52
source

1 answer

4

The problem you have is that you are rewriting the content of label every time you assign a value with lblHelper1.Text = ... .

To be able to add value after the text that already contains the label, the expression += is used:

lblHelper1.Text += ...

What has been the same thing to do:

lblHelper1.Text = lblHelper1.Text + ...
    
answered by 30.10.2017 / 14:15
source