如何从Postgres数据库检索到下拉列表?

时间:2019-08-27 08:18:08

标签: c# .net postgresql

我是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(); 
}

1 个答案:

答案 0 :(得分:1)

在您的.cs

foreach (System.Data.DataRow row in dt.Rows) 
{
    DropDownList1.Items.Add(row["f_name"].ToString()); 
}