# 下拉式選單
## 下拉式選單(非連動)
* addOpData("參數名稱","SQL語法")==要記得設定[KEY]主鍵、[DESC]排序==
### Controller
```csharp=
void l_Master_Initialing(object sender, EventArgs e)
{
//加入來自DEMOMI ID的下拉,命名為MEB_ID
addOpData("MEB_ID", " select D.ID as [KEY] , D.ID as [DESC] from TEXT D where 1=1 group by ID");
}
```
### cshtml
* 要設定ng-options,對照參數去查詢sql語法
* sql為"m.DESC as m.DESC for m in opData.參數"
```htmlmixed=
Search Form
<div class="form-group">
<label for="txtID_S" class="col-xs-4 control-label">編號</label>
<div class="col-xs-4">
<select name="txtID_S" class="form-control" ng-model="searchData.ID" ng-options="m.DESC as m.DESC for m in opData.MEB_ID">
<option value=""></option>
</select>
</div>
</div>
```
## 下拉式選單(連動)
:::warning
連動的下拉式選單
![](https://i.imgur.com/QDcY7xC.png)
:::
### Controller
* addOpData("參數名稱","SQL語法")==要記得設定[KEY]主鍵、[DESC]排序、[GROUP]分組==
* 連動的話,第一個的sql語法要設定**Group By**把資料群組起來
* 第二個sql就要設定==GROUP==
```csharp=
void l_Master_Initialing(object sender, EventArgs e)
{
//加入來自DEMOMI ID的下拉,命名為MEB_ID
addOpData("MEB_ID", " select D.ID as [KEY] , D.ID as [DESC] from TEXT D where 1=1 group by ID");
//連動下拉式清單
addOpData("NAME_ID", " select D.NAME as [KEY] , D.NAME as [DESC], D.ID as [GROUP] from TEXT D where 1=1 order by D.ID ");
}
```
### cshtml
* 要設定ng-options,對照參數去查詢sql語法
* sql為"m.DESC as m.DESC for m in opData.參數"
* 連動的下拉式選單則要帶filter,==**|filter:{GROUP:searchData.要連動的參數}**==
```htmlmixed=
Search Form
<div class="form-group">
<label for="txtID_S" class="col-xs-4 control-label">編號</label>
<div class="col-xs-4">
<select name="txtID_S" class="form-control" ng-model="searchData.ID" ng-options="m.DESC as m.DESC for m in opData.MEB_ID">
<option value=""></option>
</select>
</div>
</div>
<div class="form-group">
<label for="txtNAME_S" class="col-xs-4 control-label">名稱</label>
<div class="col-xs-4">
<select name="txtNAME_S" class="form-control" ng-model="searchData.NAME" ng-options="m.DESC as m.DESC for m in opData.NAME_ID|filter:{GROUP:searchData.ID}">
<option value=""></option>
</select>
</div>
</div>
```
###### tags: `實習筆記`