ASP. NET: display the voting result with an image progress bar

Source: Internet
Author: User

A voting function module can view the voting results, and display the voting results with a progress bar. The following is my method. Please do not give me any further information:
1: make an image for progress bar. You only need a small image, such as 20 Px in height and 1 px in width.

2: insert the image control in the cell to display the progress bar, and set its imageurl to the position of the completed image.

3: Use a datareader object Dr to save the number of votes taken out, use an int variable sum to save the total number of votes taken out, and define a double variable to save the number of votes divided (/) the result of the total number of votes (decimal number), and then defines an int variable to save the length of the progress bar to be displayed (the previous double variable * is used to display the length of the cell of the progress bar, and then forcibly convert to int type), assign the length to the width attribute of the image, and the following is myCodeSegment, showing four progress bars:

Sqlcommand cmd = new sqlcommand ("select * From tvotenum order by vid", con); // SQL statement used to check the voting result
Sqldatareader DR = cmd. executereader ();
......

Sqlcommand cmd1 = new sqlcommand ("select sum (vnum) from tvotenum", con1); // SQL statement used to check the total number of votes
Int sum = convert. toint32 (255.1.executescalar ());
......

Dr. Read (); // read the first record of the datareader object
This. label1.text = dr. getint32 (1). tostring (); // Number of votes for the first item
Double W1 = (convert. todouble (this. label1.text)/SUM); // percentage of the total number of votes
Int wid1 = (INT) (W1 * 310); // convert to a specific pixel. 310 indicates the length of the cell to be used to display the progress bar.
This. image1.width = wid1; // The width assigned to the image.
Dr. Read (); // read the second record
This. label2.text = dr. getint32 (1). tostring ();
Double W2 = (convert. todouble (this. label2.text)/SUM );
Int wid2 = (INT) (W2*310 );
This. image2.width = wid2;

Dr. Read (); // read the third record
This. label3.text = dr. getint32 (1). tostring ();
Double W3 = (convert. todouble (this. label3.text)/SUM );
Int wid3 = (INT) (W3*310 );
This. image3.width = wid3;

Dr. Read (); // read the Fourth Record
This. label4.text = dr. getint32 (1). tostring ();
Double W4 = (convert. todouble (this. label4.text)/SUM );
Int wid4 = (INT) (W4*310 );
This. image4.width = wid4;

Related Article

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.