<asp:DropDownList ID="DropDownList2" runat="server" DataTextField='<%# Eval("Name") %>'/>using(OleDbConnection conn = (OleDbConnection)Session["DB_CONN"])
{
OleDbCommand select = conn.CreateCommand();
select.CommandText = "select * from persons";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = select;
da.Fill(ds,"Persons");
DropDownList2.DataSource = ds.Tables[0];
DropDownList2.DataBind();
}异常说明如下:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
{
OleDbCommand select = conn.CreateCommand();
select.CommandText = "select * from persons";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = select;
da.Fill(ds,"Persons");
DropDownList2.DataSource = ds.Tables[0];
DropDownList2.DataBind();
}异常说明如下:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
<asp:TemplateColumn HeaderText="aaa">
<ItemStyle width="35%" ></ItemStyle>
<ItemTemplate>
<Common:HrmHyperLink ID="link" runat="server" Text='<%#Eval("aaa") %>' Target="_blank"></Common:HrmHyperLink>
</ItemTemplate>
</asp:TemplateColumn>
绑定的值就用, DataTextField是指定的值, 非绑定.
using(OleDbConnection conn = (OleDbConnection)Session["DB_CONN"])
{
OleDbCommand select = conn.CreateCommand();
select.CommandText = "select * from persons";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = select;
da.Fill(ds,"Persons");
name="Name";
DropDownList2.DataSource = ds.Tables[0];
DropDownList2.DataBind();
}
1.数据项目的命名容器
2.数据字段名
3.格式字符串