Asp. NET implementation with picture progress bar Display Voting Results _ practical skills

Source: Internet
Author: User
A voting function module is to view the results of the poll, with a progress bar to show that the results of each poll can have a clear effect. Here are my methods, please do not hesitate to enlighten us:
1: Make a picture for making progress bar, only need a very small picture on it, such as high 20px, wide 1px.

2: Insert the image control in the cell where you want to display the progress bar, and its ImageUrl set to the position of the finished picture.

3: With a DataReader object Dr Save the number of votes taken out, with an int variable sum save the total number of votes taken out, each of which defines a double variable to hold the number of individual votes divided by (/) The total number of votes (decimal), Define an int variable to hold the length of the progress bar that you want to display (the length of the cell that is used to display the progress bar in the preceding double variable *). then cast to int), assign the length to the width property of the picture, and the following is my code fragment showing four progress bars:

SqlCommand cmd=new SqlCommand ("SELECT * from Tvotenum ORDER by Vid", con);//SQL statement to find out the voting results of each item
SqlDataReader Dr=cmd. ExecuteReader ();
......

SqlCommand cmd1=new SqlCommand ("Select sum (vnum) from Tvotenum", con1);//SQL statement that finds the total number of votes
int Sum=convert.toint32 (CMD1. ExecuteScalar ());
......

Dr. Read ();//reads the first record of the DataReader object
This. Label1.text=dr. GetInt32 (1). ToString ()///number of votes in the first item
Double w1= (convert.todouble (this. Label1.Text)/sum);//The percentage of the total number of votes
int wid1= (int) (w1*310);//translate to a specific pixel, 310 is the length of the cell to use to display the progress bar
This. image1.width=wid1;//assignment to the width of the picture
Dr. Read ()//reading 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 ()//reading 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 ()//reading 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.