How to Make Gridview Column Selection in a Loop using asp.net C#

孤者浪人 提交于 2021-02-17 06:10:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!