我有这样的网格:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="StudentNum" DataSourceID="SqlDataSource1" Width="1314px">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ItemStyle-CssClass="ColVisible" HeaderStyle-CssClass="ColVisible" FooterStyle-CssClass="ColVisible"/>
<asp:BoundField DataField="StudentNum" HeaderText="Student Number" ReadOnly="True" SortExpression="StudentNum" />
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
<asp:BoundField DataField="Surname" HeaderText="Surname" ReadOnly="True" SortExpression="Surname" />
<asp:BoundField DataField="Degree" HeaderText="Degree" ReadOnly="True" SortExpression="Degree" />
<asp:BoundField DataField="Average" HeaderText="Average" ReadOnly="True" SortExpression="Average" />
</Columns>
</asp:GridView>
在打印按钮上,我写了以下内容:
<asp:Button ID="btnPrintCurrent" runat="server" Text="Print"
OnClientClick="doPrint()" />
并打印我写的Javascript:
<script type="text/javascript">
function doPrint() {
var strContent = "<html><head>";
strContent = strContent + "<title" + "></title>";
strContent = strContent + "<link href='App_Themes/Default.css' rel='stylesheet'/>";
strContent = strContent + "</head><body>";
strContent = strContent + "<div style='width:100%;text-align:left;'>";
strContent = strContent + "<img src='~/Images/bannerNMMULogo.png'/>";
strContent = strContent + "<h1>CS Honours Project Allocation System</h1>";
strContent = strContent + "</div>";
var prtContent = document.getElementById('<%= GridView1.ClientID %>');
strContent = strContent + prtContent.outerHTML;
prtContent.border = 0; //set no border here
var WinPrint = window.open('', '', 'left=100,top=100,width=1000,height=1000,toolbar=0,scrollbars=1,status=0,resizable=1');
WinPrint.document.write(strContent);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
</script>
我的问题是:
- 打印预览时看不到图像
- 我想
<asp:CommandField>
在打印预览时隐藏第一列,删除/编辑按钮