當我有GridView和我想要生成的網格列 的Excel工作表有Excel中的產生代碼和按鈕的點擊。我的問題是 ,我不希望在Excel工作表中網格視圖列的模板字段。 我只想BoundField的數據字段不想網格視圖模板字段生成excel表
<asp:ImageButton ID="btnExcel" runat="server" Text="Excel" ToolTip="Excel" ImageUrl="~/Images/Resources/thumb/excel.png" OnClick="btnExcel_Click" />
protected void btnExcel_Click(object sender, ImageClickEventArgs e)
{
ExportToExcel("Repoet.xls", grdReq);
}
public void ExportToExcel(string strFileName, GridView gv)
{
HtmlForm form = new HtmlForm();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
form.Controls.Add(gv);
this.Controls.Add(form);
form.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
}
<asp:GridView ID="grdReq" runat="server" AutoGenerateColumns="false" CssClass="SimpleGrid"
OnRowDataBound="grdReq_RowDataBound">
<Columns>
<asp:BoundField DataField="CandidateID" HeaderText="Candidate Id" />
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="hlnkEvalSheet" runat="server" Text='<%#Eval("Candidate Name") %>'
CssClass="logo" NavigateUrl='<%# "~/Recruiter/EvalSheets.aspx?ClientId=" + hdnClientId.Value + "&ReqId=" + hdnReqId.Value %>'
ImageUrl="~/Images/Resources/search.png" >
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Candidate Name" HeaderText="Candidate Name" />
<asp:BoundField DataField="Organization" HeaderText="Organization" /> <asp:BoundField DataField="Desig" HeaderText="Design" />
<asp:BoundField DataField="Overall" HeaderText="Overall" />
<asp:BoundField DataField="Qualification" HeaderText="Qualification" />
<asp:BoundField DataField="Location" HeaderText="Location" />
<asp:BoundField DataField="Current CTC (LPA)" HeaderText="Current CTC (LPA)" />
</Columns>
</asp:GridView>
請點擊這裏給我解決我只想電網的數據綁定場爭奪w在Excel表格中。 – SANDEEP 2013-04-09 10:15:25