问题
Please i have the below code that upon button click event, i create a delimited string from a gridview and display it in a textbox. Currently the loop creates the delimited string using all the columns available in the gridview. How do i specify only the columns that is needed to create the delimited string. Per the image below i don't want the storeid column to be part of the delimeted string
This code is what am using to create the delimeted string
protected void CreatePOEntryString2()
{
{
string MyResults = "";
foreach (GridViewRow gRow in griditem.Rows)
{
if (MyResults != "")
MyResults += "|";
string MyRow = "";
foreach (TableCell tCell in gRow.Cells)
{
if (MyRow != "")
MyRow += ",";
MyRow += tCell.Text;
}
MyResults += MyResults;
}
txtPODetails.Text = MyResults + ItemPipe;
}
}
Thank you all
回答1:
you can simply filter out storeid
from the inner foreach (if you want to go with this approach)
foreach (TableCell tCell in gRow.Cells.where (x=>x.Text!="storeid"))
{
if (MyRow != "")
MyRow += ",";
MyRow += tCell.Text;
}
来源:https://stackoverflow.com/questions/65376204/how-to-make-gridview-column-selection-in-a-loop-using-asp-net-c-sharp