如何插入一个硬编码的值,而剩余的值将来自ASP.NET的下拉列表中的数据库?

问题描述:

我想在我的代码(Asp.net)中使用下拉列表。我想将第一个值设为硬编码(在我的情况下为选择城市),而剩余的值将来自数据库。我怎么能这样做。平均第一个值将被硬编码,而剩余部分将是动态的。



我尝试过:



< asp:DropDownList ID =ddlGenderrunat =serverWidth =200px>

< asp:ListItem Text =Select City&gt ;

I want to use drop down list in my code (Asp.net). I want to make first value as hard coded ("Select City" in my case) while remaining values will come from database. How i can do that. Mean first values will be hard coded, while remaining will be dynamic .

What I have tried:

<asp:DropDownList ID="ddlGender" runat="server" Width="200px">
<asp:ListItem Text="Select City" >

试试这样



try like this

var itemsFromDb = getData();
for (int i = 0; i < itemsFromDb.Length; i++)
    ddlGender.Items.Add(itemsFromDb[i]);