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();
相关文档:
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 ......
为了忘记:
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 的回调技术后不是很理解。还是把写的东西贴下,自己以后学习时候多看看。前台index.aspx页<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace = "System.Text" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit ......
1、定义CS类 using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using Hash ......
ASP.NET中,若要将一个URL参数值赋值给一个变量,都得先判断参数是否存在,否则等待你的很可能就是"未将对象引用设置到对象的实例",以前都是
Request.QueryString["xx"] != null比较后再赋值,但今天在一个项目中发现竟还报错,代码大致结构如下:
复制内容到剪贴板
程序代码
int id = 0;
if (R ......