![](/img/trans.png)
[英]hide/show specific number of items from asp.net repeater using jquery or javascript
[英]asp.net Hide Specific items in dropdownlist using javascript
我正在使用ASP.NET,我正在動態填充我的DropDownList。 這是我的代碼:
DataTable dtList = new DataTable();
dtList.Columns.Add("Name");
dtList.Columns.Add("Type");
foreach (DataDefinitionResponse dr in _dr)
{
if (dr.Type == "Dropdown")
{
string[] strSplit = dr.ListValue.Split('|');
List<string> lst = new List<string>();
foreach (string word in strSplit)
{
DataRow row = dtList.NewRow();
row["Name"] = word;
row["Type"] = dr.Name;
dtList.Rows.Add(row);
}
}
}
ddlFieldList.DataSource = dtList;
ddlFieldList.DataTextField = "Name";
ddlFieldList.DataValueField = "Type";
ddlFieldList.DataBind();
現在我只想在選擇另一個DropDownList時使用Javascript隱藏特定項目。 我這里沒有使用SelectedIndexChanged。 我必須使用Javascript。
請有人幫我這個。
謝謝
我認為你不能用JavaScript操縱DropDownList並“僥幸逃脫”,因為當頁面隨后被發回服務器時,ASP .NET將檢測到DropDownList已被“篡改”並將拋出一個例外。
您可以設置標志來停止錯誤,但您不太可能在代碼隱藏中使用DropDownList。
您通常會使用SelectedIndexChanged
(我知道您說過您不想這樣做)嘗試實現,並將控件放在UpdatePanel
或類似內容中以避免整頁回發/刷新。
function Remove()
{
var DropDownList=document.getElementById('<%=DropDownList1.ClientID%>');
alert(DropDownList.value);
for(i=DropDownList.length-1; i>=0; i--)
{
if(DropDownList.options[i].selected)
{
DropDownList.remove(i);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.