ASP. NET2.0 website development (7) Development Homepage

Source: Internet
Author: User

The home page is a software portal and is particularly important in design. This page is developed and configured in this section. The home page of this software is used to display the book data stored in the library, this section focuses on the use of DataList and the reading of images stored in the library files.

Create a new Web page named Default. aspx. Use the master page. After the page is generated, it is displayed as the combination of the master page and the derived page:

Set a DataList control in the region on the derived page and add template settings:

<Table cellpadding = "4" cellspacing = "0" style = "width: 100%;">
<Tr class = "smalltxt">
<Td class = "altbg1" style = "width: 220px" align = "center">
<Asp: Image ID = "Image1" runat = "server"
ImageUrl = ''Height =" 180px "Width =" 150px "/> </td>
<Td class = "altbg2">
& Lt; table width = "100%" & gt;
<Tbody>
<Tr>
<Td style = "width: 100px; height: 30px;">

Book name </td>
<Td>
<Asp: Label runat = "server" Text = '<% # Eval ("Mc") %>'/>
</Td>
</Tr>
<Tr style = "height: 30px;">
<Td> press </td>
<Td>
<Asp: Label runat = "server" Text = '<% # Eval ("cbs") %>'/>
</Td>
</Tr>
<Tr style = "height: 30px;">
<Td> pricing </td>
<Td>
<Asp: Label ID = "Label1" runat = "server" Text = '<% # Eval ("Dj") %>'/>
</Td>
</Tr>
<Tr style = "height: 30px;">
<Td> contents </td>
<Td>
<Asp: Label ID = "Label2" runat = "server" Text = '<% # Eval ("Nrty") %>'/>
</Td>
</Tr>
</Tbody>
</Table>
</Td>
</Tr>
</Table>

In the template, use the Label control to display the data in the database and locate the data in the Table.

There are two ways to save images in a program: one is to save the image path information in the library file and save the image files in a separate directory, when using the Image control, direct the Image to the Image path to display the file. This is relatively simple. The other is to save the file directly in the database and use the functions provided by the database, however, reading and writing is more troublesome than the first method. This software uses the second method.

In ASP. NET2.0, the image stream saved in the library file cannot be directly used and must be converted. Create a new web file without using the master page. Write the following code in the Load of the new file:

If (! Page. IsPostBack)
{
Int id = Convert. ToInt32 (Request. QueryString ["id"]);

Byte [] imagepicture = new DALClass (). Books_GetValue (id). Tp;

Response. ContentType = "image/JPEG ";
Response. BinaryWrite (imagepicture );
}

That is, read the stream data of the image and write the stream data to the Http output. You can use this file when displaying the image. Modify the image position in Default. aspx

<Asp: Image ID = "Image1" runat = "server"
ImageUrl = '<% # "getpic. aspx? Id = "+ Eval (" Id ") %> 'height =" 180px "Width =" 150px "/> </td>

During execution, the Default. aspx is sent to getpic. aspx based on the unique ID of the display record. After the Image data is queried by getpic. aspx, it is written to the Http stream and returned, which is displayed by the Image control.

Interface for software running:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.