易截截图软件、单文件、免安装、纯绿色、仅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中HttpMoudule初始化程序

为了忘记:
1,System.Web.Hosting.ISAPIRuntime.ProcessRequest(IntPtr, Int32);:void
//从IIS来的请求
2,System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest) : Void
//在这一步创建一个HttpContext对象
3, System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext) : IHttpHandler
// ......

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中绑定时间的格式化

一直以来将数据库中的时间绑定到gridview中后,显示的后面总是会多出一串00:00:00,
原来是绑定的时候没有格式化字符串,只要在绑定时加入如下格式就对了。
<asp:BoundField DataField="FieldName" HeaderText="时间" DataFormatString="{0:d}" HtmlEncode="false"> ......

ASP.NET 3.5 中的数据绑定

    ASP.NET 3.5中6个内置的数据源控件分别用于特定类型的数据访问。
SqlDataSource 控件   允许访问支持ADO.NET数据提供程序的所有数据源。该控件默认可以访问ODBC、OLE DB、SQL Server、Orale和SQL Server CE 提供程序
LinqDataSource  控件 可以使用LINQ 查询访问不同类型的数据对象
O ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号