在 asp.net 中填充下拉列表的最简单方法是什么(代码隐藏)?我刚刚学会了如何使用数据表和数据适配器填充网格。可以使用数据表和数据适配器来填充 dropdonlist 吗?这是我的尝试..
public partial class page3 : System.Web.UI.Page
{
public DataTable fillmydropdownlist()
{
DataTable drpdt = new DataTable();
string q = "select flightdate from flightdetails";
SqlCommand cmd = new SqlCommand(q,con);
try
{
SqlDataAdapter da2 = new SqlDataAdapter(cmd);
}
catch { }
return drpdt;
}
protected void Page_Load(object sender, EventArgs e)
{
dbOperation dbo = new dbOperation();
DataTable dt = new DataTable();
dt = dbo.fillmydropdownlist();
DataTable drpdt= new DataTable();
if (dt.Rows.Count > 0)
{
DropDownList1.DataSource = drpdt;
DropDownList1.DataBind();
}
else
{
Response.Write("No Data");
}
}
}