Because the Image control in asp.net is in the System. Web. UI. WebControls namespace, you cannot directly display images through byte [] as in winform.
In this case, we can only save the country. Here is an example of the idea: teacherdetial. aspx is the final page used to display text and images, but because our images need to save the country by curve, another pic. aspx is created here. On the pic. aspx page, the Image is displayed, and the url of the Image control in teacherdetial. aspx is set to pic. aspx. Finally, we completed the requirements.
The code for teacherdetial. aspx is as follows:
Copy codeThe Code is as follows:
<Td height = "25" align = "right"> photo: </td>
<Td>
<Asp: Image ID = "Image1" runat = "server" Width = "80" Height = "80"/>
</Td>
The code for teacherdetial. aspx. cs is as follows:
Copy codeThe Code is as follows:
Private string tid = null;
Protected void Page_Load (object sender, EventArgs e)
{
Tid = Request. Params ["tid"];
This. Image1.ImageUrl = "~ /Teacher/pic. aspx? Tid = "+ tid;
}
In this way, the Image display function is transferred to another page, and our Image control only displays the other page.
The pic. aspx code is very simple. You just need to create a new page.
The pic. aspx. cs code is as follows:
Copy codeThe Code is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
String tid = Request. Params ["tid"]. ToString ();
TeacherDao td = new TeacherDao ();
Response. BinaryWrite (td. getPic (tid ));
}