Steven Tagoe

Steven Tagoe

  • NA
  • 151
  • 714

Select Specific Column in Gridview Template Field using Loop in C#

Dec 20 2020 1:31 PM

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.Now my task is to

  1. Use template textbox field inside the gridview instead of the normal gridview default
  2. I don't need all the columns to create the delimited string.I need Specific columns Only. So now do how i specify only the columns i need to create the delimited string using template textbox fields. Per the image below i don't want the storeid column to be part of the delimited string
Below is also the working code which does not use template fields
  1. protected void CreatePOEntryString2()  
  2. {  
  3.     {  
  4.         string MyResults = "";  
  5.   
  6.         foreach (GridViewRow gRow in griditem.Rows)  
  7.         {  
  8.             if (MyResults != "")  
  9.                 MyResults += "|";  
  10.             string MyRow = "";  
  11.   
  12.             foreach (TableCell tCell in gRow.Cells)  
  13.             {  
  14.                 if (MyRow != "")  
  15.                     MyRow += ",";  
  16.                 MyRow += tCell.Text;  
  17.             }  
  18.             MyResults += MyResults;  
  19.         }  
  20.         txtPODetails.Text = MyResults + ItemPipe;  
  21.     }  

 Thank you

Answers (1)