동적으로 채워지는 ListBox가 있습니다. ListItem의 값이 특정 문자열과 일치하는 경우 선택한 각 ListItem을 "선택됨"으로 표시하고 싶습니다.
ASP.NET :
<asp:ListBox ID="lstComputers" runat="server"></asp:ListBox>
씨#:
//code that populates lstComputers.
//I got this part working properly already
자바 스크립트 :
//I'm really bad at javascript, so here's the sudo code of what I'd like done
For each ListItem in lstComputers{
If ListItem.value like 'HP%' then{ //assuming % is like a wild card in SQL
ListItem.selected = true;
}
}
JavaScript로 도와주세요.
감사
이 시도:-
function SelectListBox() {
var lstComputers = document.getElementById("<%= lstComputers.ClientID %>");
for (var i = 0; i < lstComputers.options.length; i++) {
if (lstComputers.options[i].text.indexOf("HP") > -1) {
lstComputers.options[i].selected = true;
}
}
}
또한 ListBox 컨트롤에서 다중 선택을 원하는 경우 SelectionMode
속성을로 설정 했는지 확인하십시오 Multiple
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다