易截截图软件、单文件、免安装、纯绿色、仅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();


相关文档:

ASP.NET于Excel的交互

public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
Ole ......

ASP.NET中常用的三十三种代码

1. 打开新的窗口并传送参数 [返回目录]
传送参数: 
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>") 
接收参数: 
string a = Request.QueryString("id"); 
string b = Request.QueryString("id1"); 
2.为按钮 ......

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

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

ASP.NET 3.5 中的数据绑定

    ASP.NET 3.5中6个内置的数据源控件分别用于特定类型的数据访问。
SqlDataSource 控件   允许访问支持ADO.NET数据提供程序的所有数据源。该控件默认可以访问ODBC、OLE DB、SQL Server、Orale和SQL Server CE 提供程序
LinqDataSource  控件 可以使用LINQ 查询访问不同类型的数据对象
O ......

asp.net___web.config详解 (转载)

在开发中经常会遇到这样的情况,在部署程序时为了保密起见并不将源代码随项目一同发布,而我们开发时的环境与部署环境可能不一致(比如数据库不一样),如果在代码中保存这些配置这些信息部署时需要到用户那里更改代码再重新编译,这种部署方式非常麻烦。
在.net中提供了一种便捷的保存项目配置信息的办法,那就是利用配置 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号