【问题标题】:How to Make Gridview Column Selection in a Loop using asp.net C#如何使用 asp.net C# 在循环中进行 Gridview 列选择
【发布时间】:2021-03-30 09:17:19
【问题描述】:

请我有下面的代码,在按钮单击事件时,我从 gridview 创建一个分隔字符串并将其显示在文本框中。目前,循环使用 gridview 中可用的所有列创建分隔字符串。如何仅指定创建分隔字符串所需的列。 根据下图,我不希望 storeid 列成为分隔字符串的一部分

这段代码是用来创建分隔字符串的

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;
        }
    }

谢谢大家

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    您可以简单地从内部 foreach 中过滤掉 storeid(如果您想采用这种方法)

    foreach (TableCell tCell in gRow.Cells.where (x=>x.Text!="storeid"))
            {
                if (MyRow != "")
                    MyRow += ",";
                MyRow += tCell.Text;
            }
    

    【讨论】:

      猜你喜欢
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 2010-11-10
      • 2012-11-28
      • 1970-01-01
      • 2021-03-20
      • 1970-01-01
      相关资源
      最近更新 更多