易截截图软件、单文件、免安装、纯绿色、仅160KB

asp.net 2.0 怎样对label进行绑定

问题描述:
数据库A表中:
ID    Name
1    小明
2    小强
3    小张
4    小李
5    小关
...
分别有Label1,Label2... Label5 五个标签,怎么让这五个标签Text绑定显示A表Name列的前5个,就是说Label1显示小明,Label2显示小强... 
原帖地址 :  http://topic.csdn.net/u/20080325/21/057A65A7-4224-457B-9AE8-25C4CBE6F16E.html
代码如下:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text='<%# GetText((sender as Label).ID.Substring(5)) %>'></asp:Label><br />
<asp:Label ID="Label2" runat="server" Text='<%# GetText((sender as Label).ID.Substring(5)) %>'></asp:Label><br />
<asp:Label ID="Label3" runat="server" Text='<%# GetText((sender as Label).ID.Substring(5)) %>'></asp:Label><br />
<asp:Label ID="Label4" runat="server" Text='<%# GetText((sender as Label).ID.Substring(5)) %>'></asp:Label><br />
<asp:Label ID="Label5" runat="server" Text='<%# GetText((sender as Label).ID.Substring(5)) %>'></asp:Label><br />
</div>
</form>
</body>
</html>

IDictionary<int, string> dic = new Dictionary<int, string>();
protected string GetText(object index)
{
index = index ?? "";
int key;
int.TryParse(index.ToString(), out key);
return dic[key];
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dic.Add(1, "小明");
dic.Add(2, "小强");
dic.Add(3, "小张");
dic.Add(4, "小李");
dic.Add(5, "小关");
DataBind();


相关文档:

flex与asp.net互操作系统,基于Socket的网络连接

Flash/Flex也支持基于Socket的网络连接 ,服务器端可以是C++,VB,C#,Java等任一语言开发。监听一个网络端口便可以接收到Flash/Flex开发的客户端的连接。     
     ActionScript 3.0提供了通过Socket连接的方式与服务器端通信。这点是超越传统B/S结构的重要特征。这样使得网 ......

asp.net使用cookies

方法1:
Response.Cookies["username"].Value="gjy";
Response.Cookies["username"].Expires=DateTime.Now.AddDays(1);
方法2:
System.Web.HttpCookie newcookie=new HttpCookie("username");
newcookie.Value="gjy";
newcookie.Expires=DateTime.Now.AddDays(1);
Response.AppendCookie(newcookie);
创建带 ......

ASP.NET Web Service协议相关

=================================================================================
How to enable an ASP.NET WebService to listen to HTTP POST calls
=================================================================================
Imagine you developed an ASP.NET WebService, but the client that nee ......

使用ASP.NET MVC(C#)15分钟内创建一个电影数据库程序

    这篇教程的目的是让你体会一下创建一个 ASP.NET MVC 程序是一种什么样的感觉。在这篇教程里,我通过从头到尾地创建一整个ASP.NET MVC程序来进行说明。我会教你如何创建一个简单的数据库驱动程序,此程序会演示你如何以列表显示、新建和编辑数据库记录。
    为了简化我们创建程序的过程 ......

ASP.NET如何读取Excel文件的多张工作表

测试环境:windows server 2003+visual studio 2008
    ''' <summary>
    ''' 获取Excel文件所有工作表的名称
    ''' </summary>
    ''' <param name="iSubPath">Excel文件路径,如:D:\test.xls</param>
    ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号