ASP.net C# GridView to html table not working -


so have on mark up:

<asp:gridview id="gridview1" runat="server" itemtype="ir_infantrecord.models.immunization" datakeynames="immunizationnumber" selectmethod="patientimmungrid_getdata" autogeneratecolumns="false"              ...             <columns>                  <asp:templatefield headertext="empname">                     <itemtemplate>                     <asp:label text="<%# item.emp.empname%>"                         runat="server" />                     </itemtemplate>                 </asp:templatefield>                  <asp:templatefield headertext="check">                     <itemtemplate>                     <asp:label text="<%# item.emp.check%>"                         runat="server" />                     </itemtemplate>                 </asp:templatefield>                  <asp:dynamicfield datafield="status" />                 <asp:dynamicfield datafield="datetaken" />                          ...         </asp:gridview> 

and here on .cs class:

public static string convertgvtohtml(gridview gv)     {         string html = "<table>";         //add header row         html += "<tr>";         (int = 0; < gv.columns.count; i++)             html += "<td>" + gv.columns[i].headertext + "</td>";         html += "</tr>";         //add rows         (int = 0; < gv.rows.count; i++)         {             html += "<tr>";             (int j = 0; j < gv.columns.count; j++)                 html += "<td>" + gv.rows[i].cells[j].text.tostring() + "</td>";             html += "</tr>";         }         html += "</table>";         return html;     } 

which found here on stackoverflow,the header works fine, rows returning null. im using print gridview pdf using itextsharp.

this method works other gridview. dont know why returns null on specific gv.

for templatefield label, value not in cell text in label control (which second control of cell, after literal control):

for (int = 0; < gv.rows.count; i++) {     html += "<tr>";      (int j = 0; j < gv.columns.count; j++)     {         tablecell cell = gv.rows[i].cells[j];          html += "<td>";          if (cell.controls.count > 1 && cell.controls[1] label)         {             label lblvalue = cell.controls[1] label;             html += lblvalue.text;         }         else         {             html += cell.text;         }          html += "</td>";     }      html += "</tr>"; } 

by way, kept string concatenation technique shown in code preferable use stringbuilder.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -