Happy Bee
Happy Bee

Reputation: 71

How to retrieve from postgres db to dropdown list?

I'm newbie in c# and not familiar with its syntax. Need some help here. I would want to retrieve database data into my dropdownlist. How can i replace the following textbox for dropdownlist?

This is my dropdownlist:

<asp:DropDownList ID="DropDownList1" runat="server" OnClick="btnFilterID_Click"></asp:DropDownList> 

This is the loop to retriev textbox.

foreach (System.Data.DataRow row in dt.Rows) 
{ 
    txtFname.Text = row["f_name"].ToString(); 
}

Upvotes: 0

Views: 87

Answers (1)

Gabriel Llorico
Gabriel Llorico

Reputation: 1803

in your .cs

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

Upvotes: 1

Related Questions