RadComboBoxに空の文字列を追加します
-
12-09-2019 - |
質問
私は、ページ上のTelerikのRadComboBoxを持つWebページを持っています。このコンボボックスの特性の1つは、アイテムが選択されていない場合にメッセージを表示してコンボボックスを充填EmptyMessage、です。私は、実行時にデータソースへの私のコンボボックスをバインドしていますし、何らかの理由で、それはこのEmptyMessageを払拭します。タクトに私のデータ項目を維持し、あまりにもそこに空のメッセージを持ってする方法はありますか?そして、空のメッセージにそれをデフォルト?
解決
Telerikの受け入れ答えのように思えるが、テキストの編集を防ぐために、クライアント側のスクリプトを使用することを述べています。
<のhref = "http://www.telerik.com/community/forums/aspnet-ajax/combobox/how-can-i-show-a-message-at-the-top-of-combobox-同じような選択-item.aspx」のrel = "noreferrer"> Telerikフォーラムページ
<telerik:Radcombobox ID="RadComboBox1" runat="server" AllowCustomText="True" EmptyMessage="-please select one-">
<Items>
<telerik:RadComboBoxItem runat="server" Text="Item1"></telerik:RadComboBoxItem>
<telerik:RadComboBoxItem runat="server" Text="Item2"></telerik:RadComboBoxItem>
</Items>
<script type="text/javascript">
function pageLoad()
{
var combo = $find("<%= RadComboBox1.ClientID %>");
var input = combo.get_inputDomElement();
input.onkeydown = onKeyDownHandler;
}
function onKeyDownHandler(e)
{
if (!e)
e = window.event;
e.returnValue = false;
if (e.preventDefault)
{
e.preventDefault();
}
}
</script>
他のヒント
RadComboBox1.Items.Insert(0, New RadComboBoxItem("Select a continent"))
このは、コンボボックスの最初の項目として「大陸を選択し、」追加されます。
これだけを置く
ComboBox.Text = String.Empty
は、設計時にはEmptyMessageプロパティを設定します。
<telerik:RadComboBox ID="ddlCategory" EmptyMessage="-Select-" runat="server" Width="120px" DropDownWidth="100px" AllowCustomText="true">
</telerik:RadComboBox>
実行時に次のコードは、私のために動作します。
ddlCategory.Text = "";
ddlCategory.ClearSelection();
trueに 'AppendDataBoundItems' 設定されていますか?
別のオプションは、右結合し、次に選択されたとして、それを設定した後コンボボックスに項目を追加することです。
私は答えを見つけました。好奇心誰かこれまでに同様のことを行う必要がある誰かのためには、TrueにAllowCustomTextプロパティを設定する必要があります。これは私の問題を修正します。