【发布时间】:2018-05-13 06:04:51
【问题描述】:
我正在尝试实现一个下拉菜单,其中包含数字 1 - 数据库中的值。
我可以在下拉列表中显示数据库中的值,但无法获取从 1 开始的数字以作为下拉列表中的选项创建。
下面是我的asp代码:
<asp:SqlDataSource
ID="selectSprintLength"
runat="server"
ConnectionString="<%$ ConnectionStrings:scConnection %>"
SelectCommand="SELECT * FROM sc_sprints WHERE scSprintID = @sprint">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="sprint" Name="sprint" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="sprintLengthDropDown"
runat="server"
OnSelectedIndexChanged="sprintDropDown_SelectedIndexChanged"
DataSourceID="selectSprintLength"
DataTextField="scSprintTotal"
DataValueField="scSprintTotal"
AutoPostBack="true"
EnableViewState="true" />
这是我的 C# 代码:
protected void sprintDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
int counter = 0;
int x = Int32.Parse(sprintLengthDropDown.SelectedValue);
do
{
counter++;
}
while (counter < x);
}
任何人都可以帮忙,以便值 1 - scSprintTotal 是下拉列表中的所有选项。例如 scSprintTotal 为 7,下拉值将为 1、2、3、4、5、6、7。
提前致谢!
【问题讨论】: