在数据库

时间:2015-06-02 01:45:28

标签: c# asp.net

我有一个下拉框,下拉框中的值不一致。示例 - 从数据库中获取最大值和最小值,并在下拉列表中显示从max到min的值。像min值是3,max是7,所以显示的值是3,4,5,6,7。 这就是我在想的但是如何在下拉列表中实现或调用该函数,有人可以帮我详细说明,从昨晚开始努力解决这个问题,

MaxMinSkillLevel minMax = CompetencyManager.GetMaxAndMinSKillLevelBySkillName(lblname.Text);


        //    List<string> DDLlist = new List<string>();
        //    for (int i = Int32.Parse(minMax.minimumLevel); i < Int32.Parse(minMax.maximumLevel); i++)
        //    {
        //        DDLlist.Add((i + 1).ToString());

        //    }

2 个答案:

答案 0 :(得分:1)

如果我理解你的问题。

在您的页面加载中,您可以执行以下操作:

void Page_Load(Object sender, EventArgs e)
  {

        if (DDLlist==null)
        {
          MaxMinSkillLevel minMax = CompetencyManager.GetMaxAndMinSKillLevelBySkillName(lblname.Text);

          DDLlist = new List<string>();
          for (int i = Int32.Parse(minMax.minimumLevel); i < Int32.Parse(minMax.maximumLevel); i++)
          {
            DDLlist.Add((i + 1).ToString());
          }
        }
     // Load data for the DropDownList control only once, when the 
     // page is first loaded.
     if(!IsPostBack)
     {

        // Specify the data source
        YourDropDownList.DataSource = DDLlist;

        // Bind the data to the control.
        YourDropDownList.DataBind();

        // Set the default selected item, if desired.
        YourDropDownList.SelectedIndex = 0;

     }

  }

答案 1 :(得分:1)

试试这个

MaxMinSkillLevel minMax = CompetencyManager.GetMaxAndMinSKillLevelBySkillName(lblname.Text);
int min = Int32.Parse(minMax.minimumLevel);
int max = Int32.Parse(minMax.maximumLevel);

//Enumerable.Range(start, count)
List<int> skills = Enumerable.Range(min, (max - min) + 1).ToList();

skillsDropDown.DataSource = skills;
skillsDropDown.DataBind();