这是源绑定
首先在aspx的源里加入,假设这个aspx名字为bjbm.aspx
<%# DataBinder.Eval(Container.DataItem,"DMSM1").ToString() %>
加在什么位置不要紧,只要是上边的代码加在源里即可
DMSM1为数据库表中的[color=red]字段名[/color]
例:
<asp:Label ID = "lblViewBMMC" Text = <%# DataBinder.Eval(Container.DataItem,"DMSM1").ToString() %> runat = "server" ></asp:Label>
这是源里代码
下边是cs文件代码,bjbm.aspx.cs
进入页面即被加载
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
BLL.deptInfo.Dept bllBJBM = new BLL.deptInfo.Dept();
dt = bllBJBM.get_deptInfo_deptName().Tables["dzjc.dzjc_code"];
dltBJBM.DataSource = bllBJBM.get_deptInfo_deptName().Tables["dzjc.dzjc_code"]; ;
dltBJBM.DataBind();
ds.Dispose();
}
bllBJBM.get_deptInfo_deptName()方法为:
public DataSet get_deptInfo_deptName()
{
DAL.deptInfo.Dept dalSelectBM = new DAL.deptInfo.Dept();
return dalSelectBM.view_BM();
}
dalSelectBM.view_BM()方法为
public DataSet view_BM()
{
StringBuilder selectSql = new StringBuilder();
selectSql.Append("SELECT distinct dmsm1 ");
selectSql.Append("FROM dzjc.dzjc_code where dmlb = 2 ");
DBCommon.OracleHelper oh = new DBCommon.OracleHelper(new OracleConnectionSql().readConSql());
return oh.createDS(selectSql.ToString(),"dzjc.dzjc_code");
}
oh.createDS()方法为
public DataSet createDS(string sql, string tableName)
{
oDtr = this.createOracleDtr(sql);
oDtr.Fill(ds, tableName);
this.closeOracleCon();
return ds;
}
黑色头发:http://heisetoufa.iteye.com