如何使用asp.net C#在循环中进行Gridview列选择 [英] How to Make Gridview Column Selection in a Loop using asp.net C#
问题描述
请给我下面的代码,在单击按钮事件时,我从gridview创建一个定界的字符串,并将其显示在文本框中.当前,循环使用gridview中所有可用的列创建定界字符串.如何仅指定创建带分隔符的字符串所需的列.根据下面的图片,我不希望storeid列成为变色字符串的一部分
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;
}
}
谢谢大家
推荐答案
您可以简单地从内部foreach过滤出 storeid
(如果您想使用此方法)
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;
}
这篇关于如何使用asp.net C#在循环中进行Gridview列选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!