我有一个 RadGrid,其中我的一个列是 GridTemplateColumn,它有一个加载一些项目的 RadComboBox(编辑模式设置为“PopUp”)。我想要的是,如果在 RadComboBox 中搜索项目时,没有找到项目,那么给用户一个添加新项目的选项。目前,仅出于测试目的,如果未找到任何项目,我希望能够显示一条消息。这是我到目前为止所尝试的。
RadGrid 中的我的 RadComboBox 定义如下:
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="Product_PKRadComboBox"
ShowDropDownOnTextboxClick="false" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
EnableLoadOnDemand="true" EnableAutomaticLoadOnDemand="true" ItemsPerRequest="10"
OnItemsRequested="Product_PKRadComboBox_ItemsRequested" AllowCustomText="true"
Filter="StartsWith" DataSourceID="SqlProducts" DataTextField="ProductCode"
DataValueField="Product_PK"></telerik:RadComboBox>
</EditItemTemplate>
所以我正在“OnItemsRequested”事件中检查我的逻辑,如下所示:
protected void Product_PKRadComboBox_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
//RadComboBox combo = (RadComboBox)sender;
if (e.EndOfItems && e.NumberOfItems==0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "testMessage", "alert('Product Not Found. Do you want to add a Custom Product?');", true);
//Page.ClientScript.RegisterStartupScript(typeof(Page), "some_name", "if(confirm('here the message')==false)return false;");
}
}
我尝试了 IF 语句中的两行代码(检查用户在 RadComboBox 中键入的内容是否存在,如果它不返回任何项目,则显示一条消息),但它们似乎都不起作用。我在调试模式下尝试了相同的操作,并在 IF 语句中的行上设置了一个断点,它实际上确实执行了,但我看不到警报。