I'm trying to select and item from a dropdown

2019-06-02 05:07发布

问题:

I found a solution to choosing a fixed selection from a dropdown list. Now all I have to do is figure out how to choose an item based on the choices.

The following chooses the first item in the dropdown, however, I found out that making the dropdown "open" is not necessary.

Changing the select parameter to 2 chooses the second item in the list etc.

I suppose trying to use getElementById and cycling through the innerText may be the way to go, since I don't know any other way.

ie.Document.parentWindow.execScript "$('#drgdTankCrude').data('kendoGrid').dataItem($('#Tank_ID').data('kendoDropDownList').select(1));"

Here a section of the web page code.

 <input name="Tank.ID" id="Tank_ID" style="width: 200px; display: none;" type="text" data-role="dropdownlist"></span>

'Lots of other stuff in here for formatting

<div class="k-widget k-grid" id="drgdTankCrude" style="left: 890.32px; top: 93.7px; display: block; position: absolute;" data-role="grid">

<table class="k-selectable" role="grid" style="-ms-touch-action: double-tap-zoom pinch-zoom;" data-role="selectable">

  <colgroup><col><col></colgroup>

  <thead class="k-grid-header" role="rowgroup">

    <tr role="row">
      <th class="k-header" scope="col" data-title="Tank" data-index="0" data-field="ID"><span class="k-link">Tank</span></th>
      <th class="k-header" scope="col" data-title="Capacity" data-index="1" data-field="Capacity"><span class="k-link">Capacity</span></th>
    </tr>
  </thead>
  <tbody role="rowgroup">
       <tr class="k-state-selected" aria-selected="true">
        <td>179800</td>
        <td>202.06</td></tr>
       <tr class="k-alt" aria-selected="false">
        <td>179801</td>
        <td>202.82</td>
       </tr>
    </tbody>
  </table>
</div>

'Code before dropdown

<tbody role="rowgroup">
     <tr>
        <td>179800</td>
        <td>202.06</td></tr>
     <tr class="k-alt">
        <td>179801</td>
        <td>202.82</td>
     </tr>
  </tbody>

'Code before dropdown opens

<div class="k-widget k-grid" id="drgdTankCrude" style="left: 890.32px; top: 93.71px; display: none; position: absolute;" data-role="grid">

'Code change after dropdown opens

<div class="k-widget k-grid **k-custom-visible**" id="drgdTankCrude" style="left: 890.32px; top: 93.71px; display: block; position: absolute;" data-role="grid">

'Code change after making a selection

<tbody role="rowgroup">
   <tr class="k-state-selected" aria-selected="true">
    <td>179800</td>              '<<-----This item selected
    <td>202.06</td></tr>
   <tr class="k-alt" aria-selected="false"> '<<--If selected then unselected
    <td>179801</td>                             'otherwise ends at k-alt">
    <td>202.82</td>
   </tr>
</tbody>

回答1:

The answer to selecting the first item in a kendoDropDownList ..

ie.Document.parentWindow.execScript "$('#drgdTankCrude').data('kendoGrid').dataItem($('#Tank_ID').data('kendoDropDownList').select(1));"