So I have this on my 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 my .cs class:
public static string ConvertGVToHTML(GridView gv)
{
string html = "<table>";
//add header row
html += "<tr>";
for (int i = 0; i < gv.Columns.Count; i++)
html += "<td>" + gv.Columns[i].HeaderText + "</td>";
html += "</tr>";
//add rows
for (int i = 0; i < gv.Rows.Count; i++)
{
html += "<tr>";
for (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 I found here on stackoverflow,The header works fine, but the rows are returning null. Im using this to print the gridview to pdf using ITextSharp.
This method also works with other gridview. I dont know why it returns null on this specific gv.