Click here to Skip to main content
15,894,311 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
foreach (GridViewRow row in GridView3.Rows)
      {
          if (row.RowType == DataControlRowType.DataRow)
          {
              FileUpload chkRow = (row.Cells[7].FindControl("newdoc") as FileUpload);
              if (chkRow.HasFile)
              {
                  string test = row.Cells[2].Text;
                  data = data + "" + test + ",";
              }
          }
      }

i tried put breakpoint on this line
C#
row.Cells[2].Text

result i get from test is always null/empty..any ideas why?

What I have tried:

ntggggggggggggggggggggggggggggggggggggggg
Posted
Updated 28-Nov-16 23:59pm
Comments
F-ES Sitecore 29-Nov-16 4:23am    
Use the debugger to inspect the "row" variable and expand the Cells collection to see what is in each cell and what type it is.
Karthik_Mahalingam 29-Nov-16 5:17am    
post the markup

I suspect your column number 3 is not a BoundField.
If you want to get the content of your BoundField, then you can use
C#
row.Cells[2].Text

But, if it is a template field then you need to find the control to which the text is assigned just like you have done for the FileUpload control.
i.g,
C#
Label lbl= (Label) row.FindControl("lblName");


Hope, it helps :)
Please let me know if I am missing something here.
 
Share this answer
 
Comments
KyLim0211 29-Nov-16 19:56pm    
tried change to boundfield instead of asp:TemplateField but still not working
C#
Gridview.Cells[i].Text will return value If it is a <asp:BoundField>

If you hvae Template field . you must find the control first then find the value of it . It will work.
 
Share this answer
 
Comments
KyLim0211 29-Nov-16 19:56pm    
tried change to boundfield instead of asp:TemplateField but still not working
Er. Neel Kamal 30-Nov-16 5:25am    
File upload control looses the value in Postback. Did you tried commenting the if condition , it may not be going into if condition because its always false.

try that once, if that is the issue then change the question, and better to have grid field from aspx page which you are trying to get in cs file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900