'How can I render added grid view row in render control?
I have a html file that contains gridview
<div id="divAveCostUtil" runat="server" class="row d-flex justify-content-center" style="border:1px solid #00AEC0; width:99%; margin:10px; border-radius:23px;">
<div class="d-flex justify-content-center">
<h4 style="color: #00AEC0; padding-top:10px">Average Cost & Utilization Exhibits</h4>
</div>
<div id="div_Container_acSum" class="d-flex justify-content-center">
<asp:GridView ID="gvAveCostUtil_sum" CssClass="table table-responsive-sm table-bordered table-hover gridTab" HeaderStyle-BackColor="#00AEC0" HeaderStyle-ForeColor="white" HeaderStyle-CssClass="headalign" HeaderStyle-Wrap="true" OnDataBound="gvAveCostUtil_sum_DataBound" OnRowDataBound="gvAveCostUtil_sum_RowDataBound" runat="server" EmptyDataText="GridViewHere" ShowHeaderWhenEmpty="true" AutoGenerateColumns="true" >
</asp:GridView>
</div>
</div>
Now before it renders in view I have added a header manually
protected void gvAveCostUtil_sum_DataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
TableHeaderCell cell = new TableHeaderCell();
cell.Text = "Average Cost and Utilization Exhibits - Summary";
cell.ColumnSpan = 7;
row.Controls.Add(cell);
row.BackColor = System.Drawing.Color.FromArgb(0, 174, 192);
gvAveCostUtil_sum.HeaderRow.Parent.Controls.AddAt(0, row);
}
In Grid View the data is bounded by
AveCostSumDt = currentPlan.AveCostSumReport.DataSource;
gvAveCostUtil_sum.DataSource = AveCostSumDt;
gvAveCostUtil_sum.DataBind();
Now it wokrs fine, and the header that is manually added is shown in the view, but when I render the control inorder to export it into excel
HtmlTextWriter htw = new HtmlTextWriter(stringwriter);
stringwriter = new StringWriter();
htw = new HtmlTextWriter(stringwriter);
divAveCostUtil.RenderControl(htw);
everything is in the htmltext but the datarow I added manually Average Cost and Utilization Exhibits - Summary is not in the htmltext. How Can I fix that?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
