我是C#的新手,不熟悉其语法。在这里需要一些帮助。我想将数据库数据检索到我的下拉列表中。如何替换下拉列表的以下文本框?
这是我的下拉列表:
<asp:DropDownList ID="DropDownList1" runat="server" OnClick="btnFilterID_Click"></asp:DropDownList>
这是检索文本框的循环。
foreach (System.Data.DataRow row in dt.Rows)
{
txtFname.Text = row["f_name"].ToString();
}
答案 0 :(得分:1)
在您的.cs
foreach (System.Data.DataRow row in dt.Rows)
{
DropDownList1.Items.Add(row["f_name"].ToString());
}