Asp. NET Display Gradient Picture Realization Method _ practical skills

Source: Internet
Author: User

Let me give you a final result:

To achieve the effect, first prepare a picture, height of 25pixel, width of 1 to 3pixel gradient picture. can download here.

Also prepare the data:

Dictionary<int, int> Datas 
 { 
 get 
 { 
  dictionary<int, int> d = new Dictionary<int, int> (); 
  D.add (1, km); 
  D.add (2,); 
  D.add (3); 
  return D; 
 } 
 } 

OK, the data is ready, put three label controls in ASPX, of course you can display in other controls or tags, one thing to note is width= "300", which is the gradient picture at 100% width:

<asp:label id= "Label1" runat= "Server" style= "MARGIN:3PX;" text= "" Width= "borderwidth=" 1 ></asp:label><br/> <asp:label id= " 
 Label2" runat= "Server" Style= "MARGIN:3PX;" text= "" Width= "borderwidth=" 1 ></asp:label><br/> <asp:label id= " 
 Label3" runat= "Server" Style= "MARGIN:3PX;" Text= "" "Width=" borderwidth= "1" ></asp:label><br/> 

To display the data on a label:

protected void Page_Load (object sender, EventArgs e) 
 { 
 data_binding (); 
 } 
 
 private void Data_binding () 
 { 
 int totals = m; 
 foreach (Keyvaluepair<int, int> kvp in Datas) 
 { 
  double rate = kvp. Value/(double) totals; 
 
  Double width = rate *; 
  Switch (KVP. Key) 
  {case 
  1: this 
   . Label1.Text = gradientimage (width, rate); 
   break; 
  Case 2: this 
   . Label2.Text = gradientimage (width, rate); 
   break; 
  Case 3: This 
   . Label3.text = gradientimage (width, rate); 
   break; 
  } 
 
 }} private string Gradientimage (double width, double rate) 
 {return 
 " ' + rate. ToString ("P"); 
 

The above is asp.net to realize the gradient picture method, hope to be helpful to everybody's study.

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.