填充表时,两个查询相互依赖

时间:2010-03-09 19:16:33

标签: vb.net drop-down-menu dataset focus selectedvalue

我有2个查询。一个是填充填充下拉列表的数据集,另一个填充表行的其余文本框。我想知道如何填写整个下拉列表,然后从另一个查询中选择值?

例如 -

dataset query = select hobby from hobbies
other query - select name, dob, address, hobby from employee

现在表格看起来像这样 -

Name DOB         Address       Hobby
Sam  01/10/1988  111 main st   Dropdownlist(n number of records)

现在在下拉列表中,我希望所有填充了员工表中的爱好的爱好都是选定的值。

1 个答案:

答案 0 :(得分:1)

不确定我是否理解,但是尝试使用一些伪代码

  ## fetch hobbies and employees from db
  dataset hobbies = select hobby from hobbies;
  dataset employees = select name, dob, address, hobby from employee;

  ## loop through all employees
  foreach employee in employees{

    print employee->name;
    print employee->dob;
    print employee->adress;

    ## second loop to print hobbies dropdownlist for each emplyee
    print "<select>";
    foreach hobby in hobbies{
      boolean is_selected = (employee->hobby == hobby);
      print "<option value=\"".hobby."\" selected=\"".is_selected."\">".hobby."</option>";
    }
    print "</select>";
}

这不是正确的HTML或任何东西,只是一个伪代码来证明概念。