展会信息港展会大全

asp.net绑定label的示例代码
来源:互联网   发布日期:2016-03-01 13:13:38   浏览:1552次  

导读:前台页面: 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 r...

前台页面:

<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>

后台代码:

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)

{

//如果运算符的左边是非空的就返回左边,否则是右边!

index = index ?? " ";

int key;

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

return Dic[key];

}

public void BindData()

{

Dic.Add(1, "小果");

Dic.Add(2, "小磊");

Dic.Add(3, "小组");

Dic.Add(4, "小节");

DataBind();

}

赞助本站

人工智能实验室

相关热词: 开发 编程 android

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港