Default2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected Dictionary<string, string> dic;
protected void Page_Load(object sender, EventArgs e)
{
dic = new Dictionary<string, string>();
dic.Add("1", "呵呵");
dic.Add("2", "哈哈");
}
}
Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function printdiv(divid) {
window.document.body.innerHTML = document.getElementById(divid).innerHTML;
window.print();
window.history.go(-1);
};
</script>
</head>
<body>
<div>
<select>
<option value="">请选择</option>
<%foreach (var item in dic)
{%>
<option value="<%=item.Key%>"><%=item.Value%></option>
<% }%>
</select>
</div>
<input id="btnPrint" type="button" value="打印" onclick="javascript:printdiv('divpr')" />
<div id="divpr">
<table width="300px">
<%foreach (var item in dic)
{%>
<tr>
<td><%=item.Key%></td>
<td><%=item.Value%></td>
</tr>
<% }%>
</table>
</div>
</body>
</html>