<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound1">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"userName") %>
<%=uid%>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>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.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bind();
}
}
public void Bind()
{
SqlConnection conn = new SqlConnection("Data Source=www-e4165b1eb09;Initial Catalog=mm;User ID=sa;pwd=3737");
SqlDataAdapter da = new SqlDataAdapter("select * from tb_user",conn);
DataSet ds = new DataSet();
da.Fill(ds);
this.DataList1.DataSource = ds;
this.DataList1.DataKeyField = "uid";
this.DataList1.DataBind();
}
public int uid = 0;
protected void DataList1_ItemDataBound1(object sender, DataListItemEventArgs e)
{
uid = Convert.ToInt32(this.DataList1.DataKeys[e.Item.ItemIndex]);
}
}
解决方案 »
- 求一条sql语句
- 我有一个.NET的错误,请大家帮我看一下好不。。。。 急!急!
- ASP.NET2.0设置起始页没有效果
- 给大家拜年啦!呵呵,上来感谢各位去年下半年来的帮助,让工作找上了我!
- 如何通过DataGrid显示DataSet中的多个Table?
- datagrid中代码添加列ButtonColumn后单击添加的列不能触发itemcommand事件问题求助
- 如何得到另一个网站数据库中的数据?
- SOS,SOS怎样直接将数据库的内容以xml格式显示出来
- DataList里面有个DataList,如何能够找到它?
- 怎样得到现在页面的页面编码?
- SQL Server不允许进行远程连接 设置好了 还是出错???
- ExecuteScalar Connection属性未初始化
<%=uid%>这样绑定的uid的值在数据库里面是不同的单是在DataList1_ItemDataBound1这里面绑定显示的值都是一样 大家有什么办法解决下