我如何从数据库中获取价值到下拉列表中?
问题描述:
下拉列表被自动生成序号。从数据库中选择值后,它显示与自动生成的下拉列表相同我如何从数据库中获取价值到下拉列表中?
e ddlDuration.DataSource = Enumerable.Range(1, 100);
ddlDuration.DataBind();
ddlDuration.Items.Insert(0, new ListItem("--Select Customer--", "0"));
此代码用于生成数字。
ddlDuration.SelectedIndex = ddlDuration.Items.IndexOf(ddlDuration.Items.FindByValue(oList[0].Duration));
和这个用于从列表中读取数据。值可以得到直到
oList [0]。持续时间。
答
Raheez您好,
它可以发生,因为oList的值[0] .Duration不在1-100范围内。
或者
尝试这种情况:
ddlDuration.SelectedIndex = ddlDuration.Items.IndexOf(ddlDuration.Items.FindByValue(oList [1] .Duration.Trim()));