<meta name="vs_defaultclientscript" content="javascript">
<meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
<p align="left">
<asp:datagrid headerstyle-cssclass="headerstyle" itemstyle-cssclass="itemstyledefault" runat="server" id="datagrid1" font-size="8" height="50" width="675"></asp:datagrid></p>
<p align="center">
<a href="javascript:window.close()">close window</a>
</p>
</body>
</html>
datagrid_show.aspx.cs
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
using system.data.sqlclient;
namespace study
{
/// <summary>
/// datagrid_show 的摘要说明。
/// </summary>
public class datagrid_show : system.web.ui.page
{
protected system.web.ui.webcontrols.datagrid datagrid1;
#region user defined code
private void page_load(object sender, system.eventargs e)
{
if ( ! this.ispostback )
this.binddata();
}
protected void binddata()
{
sqlcommand cmd = new sqlcommand( "select * from products where productid = @productid", con("server=dwserver; database=northwind; user id=sa; password=123456"));
cmd.parameters.add(new sqlparameter("@productid", sqldbtype.varchar, 200));
cmd.parameters["@productid"].value = request["productid"].tostring();
this.datagrid1.datasource = cmd.executereader(commandbehavior.closeconnection);
this.datagrid1.databind();
}
protected sqlconnection con(system.string connectionstring )
{
sqlconnection c = new sqlconnection( connectionstring );
c.open();
return c;
}
#endregion
#region web form designer generated code
override protected void oninit(eventargs e)
{
//
// codegen:该调用是 asp.net web 窗体设计器所必需的。
//
initializecomponent();
base.oninit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void initializecomponent()
{
this.load += new system.eventhandler(this.page_load);
}
#endregion
}
}