リストボックスからリスト(.csページ)にすべてのアイテムを追加しようとしています.javascriptを使用してリストボックスにアイテムを追加しました.今、LstScan.Items.Countは常にゼロを返します.リストボックスにアイテムを追加できません.リストボックスは値を示します.しかし私の .cs ファイルで問題が発生します。これが私のコードです。
Html および JavaScript コードは次のとおりです。
<script type="text/javascript">
function displayKeyCode_demo(e) {
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
if (code == 13) {
var textbox = document.getElementById("<%=TextBox1.ClientID%>")
var listbox = document.getElementById("<%=LstScan.ClientID%>")
var newOption = document.createElement("Option");
newOption.value = textbox.value;
newOption.innerHTML = textbox.value;
listbox.add(newOption);
}
}
</script>
<div>
<table cellspacing="3px" style="margin: 10px auto 3px 85px;">
<tr>
<td width="150px">
<asp:TextBox ID="TextBox1" runat="server" onkeypress="displayKeyCode_demo(event)"></asp:TextBox>
</td>
<td width="200px">
<asp:ListBox ID="LstScan" runat="server" Height="200px" Width="150px" AppendDataBoundItems="True" AutoPostBack="True" >
</asp:ListBox>
</td>
</tr>
</table>
</div>
これが私のコードビハインドコードです:
List<int> LstSOnum = new List<int>();
foreach (ListItem item in LstScan.Items) {
LstSOnum.Add(int.Parse(item.Value));
}