如何在Perl的分页期间保留每页中从Combobox中选择的值?

时间:2010-10-04 06:15:45

标签: javascript perl

问题在于如何在分页期间保留Combobox中的选定值。 “我有一个有一些值的组合框,当我选择1个值时,然后根据所选的值,将定义每页的记录,但每当我导航到下一页时,组合框中的值将重置为第一个值”。这是一段代码..

对于Combobox

   print qq[<td>Records PerPage</td>];
   print qq[<td><select id="combo1" onchange="getCombo1(this.options
     [this.selectedIndex].value,$pageNum)"><option value="">Select</option><option
      value="2">2</option><option value="4" >4</option><option 
      value="6">6</option><option value="10">10</option></select></td></tr>];

Javascript

  <script type="text/javascript">
function getCombo1(offset,pagenumber)
 {
        var val1=pagenumber;
        var val2=offset;
       window.location="UsersList.cgi?pageNum="+val1+"&offset="+val2
 }

分页代码

    if ( $pageNum > 0 ) {
         print qq[<tr><td><a href="UsersList.cgi?
         pageNum=0&offset=$offset&SortBy=$SortBy&SortOrder=$SortOrder">|&lt;</a></td>];
    $pageN  = $pageNum - 1;
    print qq[<td><a href="UsersList.cgi?
     pageNum=$pageN&offset=$offset&SortBy=$SortBy&SortOrder=$SortOrder">&lt;</a></td>];
                      }
    else
      { 
    print q[<td><span class="currentpage">|&lt;</span></td>];
    print q[<td><span class="currentpage">&lt;</span></td>];
       }
  if ( $pageNum < ( $numofPages - 1 )) {
    $pageN  = $pageNum + 1;
    print qq[<td><a href="UsersList.cgi?
       pageNum=$pageN&offset=$offset&SortBy=$SortBy&SortOrder=$SortOrder">&gt;</a>
       </td>];
    $tempnumpage=$numofPages-1;
    print qq[<td><a href="UsersList.cgi?
       pageNum=$tempnumpage&offset=$offset&SortBy=$SortBy&SortOrder=$SortOrder">&gt;|
       </a></td>];
    }
    else {
       print q[<td><span class="currentpage">&gt;</span></td>];
       print q[<td><span class="currentpage">&gt;|</span></td>];
          }
       my  $temppageNumber=$pageNum+1;
      print qq[<td><b> $temppageNumber of $numofPages pages</b></td>];

请帮我找到解决方案。谢谢你

2 个答案:

答案 0 :(得分:2)

您的Combobox打印代码需要在相应的“selected”中打印“<option>”属性。

为此,您需要遍历选项值,在循环中逐个打印它们;并在适当的位置(与$offset匹配)打印“selected”属性。通常采用的方式类似于:

print qq[<td>Records PerPage</td>];
print qq[<td><select id="combo1" onchange="getCombo1(this.options
  [this.selectedIndex].value,$pageNum)"><option value="">Select</option>];

foreach my $value (2, 4, 6) {
    my $selected = ($offset == $value) ? "selected" : "";
    print qq[<option value="$value" $selected>$value</option>];
}
print qq[</select></td></tr>];

答案 1 :(得分:0)

foreach(GridViewRow grRow in GridSubMenu.Rows)
{
   int i = int.Parse(GridSubMenu.DataKeys[grRow.RowIndex].Value.ToString()) -1; 

   MenuList =(DropDownList)(GridSubMenu.Rows[grRow.RowIndex].Cells[2].FindControl("ListMenu"));         

   Query = "Select menu_Id,menu_Name From tbl_menu Where menu_Id='" + int.Parse(dtSubMenu.Rows[i]["menu_Id"].ToString()) + "'";
   DataSet Menu = ObjDb.GetDataSet(Query);
   MenuList.DataTextField = "menu_Name";
   MenuList.DataValueField = "menu_Id";
   MenuList.DataSource =Menu.Tables[0];
   MenuList.DataBind();
 }