Sample code for ASP.NET binding label

Source: Internet
Author: User

Front Page:


<asp:label id= "Label1" runat= "server" text= ' <% #GetName ((sender as Label). ID. Substring (5))%> ' ></asp:Label>


<br/>


<asp:label id= "Label2" runat= "server" text= ' <% #GetName ((sender as Label). ID. Substring (5))%> ' ></asp:Label>


<br/>


<asp:label id= "Label3" runat= "server" text= ' <% #GetName ((sender as Label). ID. Substring (5))%> ' ></asp:Label>


<br/>


<asp:label id= "Label4" runat= "server" text= ' <% #GetName ((sender as Label). ID. Substring (5))%> ' ></asp:Label>





Background code:


idictionary<int, string> Dic = new Dictionary<int, string> ();


protected void Page_Load (object sender, EventArgs e)


   {   


if (! Page.IsPostBack)


       {   


Binddata ();


       }   


   }


public string GetName (object index)


   {   


//If the left side of the operator is Non-null, return to the left, otherwise it is to the right!


index = index??    " ";


int key;


Int. TryParse (index.    ToString (), out key);


  


return Dic[key];


   }   


public void Binddata ()


   {   


Dic.add (1, "small fruit");


Dic.add (2, "small lei");


Dic.add (3, "group");


Dic.add (4, "subsection");


DataBind ();


   }

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.