0

テキストボックスでアイテムを検索する必要があります。見つかった場合は、チェックリストボックスでそのアイテムを強調表示する必要があります。以下のように試しました

clbItems.Items[foundIndex].Attributes.Add("style", "background-color:#BBBBBB; color: white;");

更新パネルを削除することで機能します。

次のコードがあります

 for (int itemcount = 0; itemcount < (p as CheckBoxList).Items.Count; itemcount++)
                                        {
                                            if ((p as CheckBoxList).Items[itemcount].Text.ToUpper().StartsWith(txtClientSearch.Text.ToUpper()))
                                            {
                                                ListItem lst1 = new ListItem((p as CheckBoxList).Items[itemcount].Text);
                                                (p as CheckBoxList).Items.RemoveAt(itemcount);
                                                (p as CheckBoxList).Items.Insert(0, lst1);
                                                (p as CheckBoxList).Items[0].Attributes.Add("style", "background-color:yellow;color:Red");
                                            }

                                        }

Javascript でこれを達成する方法を教えてください。

ありがとう、ラケシュ。

4

1 に答える 1

0

これは、コードビハインドから行う方法です

  CheckBoxList1.Attributes.Add("onclick", "checkBoxList1OnCheck(this);");

JavaScript を使用する場合は、次の例を参照してください。

<form id="form1" runat="server">
 <asp:CheckBoxList id="CheckBoxList1" onclick="checkBoxList1OnCheck(this);" runat="server">
  <asp:listitem value="1">Item 1</asp:listitem>
  <asp:listitem value="2">Item 2</asp:listitem>
  <asp:listitem value="3">Item 3</asp:listitem>
 </asp:CheckBoxList>
</form>

<script type="text/javascript">
function checkBoxList1OnCheck(listControlRef)
{
 var inputItemArray = listControlRef.getElementsByTagName('input');

 for (var i=0; i<inputItemArray.length; i++)
 {
  var inputItem = inputItemArray[i];

  if ( inputItem.checked )
  {
   inputItem.parentElement.style.backgroundColor = 'Red';
  }
  else
  {
   inputItem.parentElement.style.backgroundColor = 'White';
  }
 }
}
</script>
于 2012-08-30T05:53:04.710 に答える