The show.htm file code is as follows
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<style type= "Text/css" >
body{font-family: "Microsoft Yahei", "SimSun"}
Table{border-collapse:collapse, border:1px sold #000; width:80%;margin:0px Auto;text-align:center;}
tr,td,th{border:1px Solid #000}
Th{font-weight:bold;background: #00F; color: #FFF; line-height:30px;}
td{line-height:30px;}
caption{font-size:48px;font-weight:bold;padding-bottom:20px;}
</style>
<body>
<table>
<caption> View information Results </caption>
<tr>
<td>EmpId</td>
<td> $EmpId </td>
</tr>
<tr>
<td>EmpName</td>
<td> $EmpName </td>
</tr>
<tr>
<td>EmpAge</td>
<td> $EmpAge </td>
</tr>
<tr>
<td>DelFlag</td>
<td> $DelFlag </td>
</tr>
</table>
</body>
The Show.ashx file code is as follows
<%@ WebHandler language= "C #" class= "Show"%>
Using System;
Using System.Web;
Using System.Data.SqlClient;
Using System.Configuration;
Using System.Data;
Using System.IO;
public class Show:ihttphandler {
public void ProcessRequest (HttpContext context) {
Context. Response.ContentType = "text/html";
int id;
if (int. TryParse (context. request.querystring["id"], out ID))
{
using (SqlConnection conn = new SqlConnection (GETCONNSTR ()))
{
using (SqlDataAdapter apter = new SqlDataAdapter ("select * from Employee WHERE [email protected]", conn))
{
SqlParameter par = new SqlParameter ("@id", SqlDbType.Int);
Par. Value = ID;
Apter. SELECTCOMMAND.PARAMETERS.ADD (PAR);
DataTable ds = new DataTable ();
Apter. Fill (DS);
if (ds. Rows.Count > 0)
{
String Htmlpath = context. Server.MapPath ("show.htm");
String htmlcontent = File.readalltext (Htmlpath);
Htmlcontent = Htmlcontent.replace ("$EmpId", ds. rows[0]["EmpId"]. ToString ()). Replace ("$EmpName", ds. rows[0]["EmpName"]. ToString ()). Replace ("$EmpAge", ds. rows[0]["Empage"]. ToString ()). Replace ("$DelFlag", ds. rows[0]["Delflag"]. ToString ());
Context. Response.Write (htmlcontent);
}
}
}
}
Else
{
Context. Response.Write ("parameter Error");
}
}
<summary>
Returns the connection string for the database
</summary>
<returns></returns>
public string Getconnstr ()
{
String connstr = configurationmanager.connectionstrings["ConnStr"]. ConnectionString;
return connstr;
}
public bool IsReusable {
get {
return false;
}
}
}
ASP. NET General Handler Show Detail page