【发布时间】:2020-08-14 09:38:07
【问题描述】:
过去一个小时左右我一直在用头撞墙,因为在这个看似直截了当的过程中,我无法弄清楚自己做错了什么。
这是 ASPX 页面的样子:
<%@ Page Title="Teams" Language="C#" AutoEventWireup="true" CodeBehind="TeamEntry.aspx.cs" Inherits="Team.Model" Runat="server" Debug="true"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:DropDownList
runat="server"
ID="DDL_Teams"
Width="183px">
</asp:DropDownList>
<input id="Text1" type="text" /><input id="Submit1" type="submit" value="submit" />
</form>
</body>
</html>
下面是代码:
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using Team;
namespace Team
{
public partial class TeamEntry : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (var DDL_Teams = new DropDownList())
{
DDL_Teams.DataSource = TeamsList;
DDL_Teams.DataBind();
}
}
}
List<string> TeamsList = new List<string>()
{
"Alpha", "Bravo", "Charlie", "Delta"
};
}
}
...但是当我尝试运行该页面时,我看到的只是an empty dropdown list
我尝试了其他 StackOverflow 问题中提到的与数据绑定到下拉列表相关的其他几种方法(例如,this page 中列出的方法),但均无济于事。任何帮助将不胜感激。
【问题讨论】: