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 ();
}