RadComboBox DropDownList 已从其位置分离
RadComboBox DropDownList is dittached from its place
有一个 RadGrid
,其中包含 RadcomboBox
以及旁边的 button
。
当用户键入内容并单击按钮时,数据绑定到 RadComboBox
与键入文本相关并显示在 DropdownList
.
但是这个 DropdownList
出现在 RadcomboBox
的下方很远,这会扰乱页面的外观。请参阅随附的问题快照。
我尝试设置 ExpandDirection="Down"
属性 但没有成功。
我还尝试设置 EnableScreenBoundaryDetection="false"
,这坚持
下拉列表在页面底部,所以当我滚动页面时,下拉列表总是停留在底部并且它也随着页面滚动。
此外,我设置了 HighlightTemplatedItems="true"
但它根本不起作用。
编辑:
HTML代码:
<telerik:RadMultiPage ID="RadMultiPage6" runat="server" SelectedIndex="0" Width="100%">
<telerik:RadPageView ID="RadPageView5" runat="server" Width="100%">
<%--<telerik:RadAjaxPanel ID="RadAjaxPanel5" runat="server">--%>
<telerik:RadGrid ID="RGGSTAcCode" runat="server" AutoGenerateColumns="false"
ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true"
AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
OnNeedDataSource= "rggstAcCode_NeedDataSource" OnItemDataBound="rggstAcCode_ItemDataBound"
OnInsertCommand="rggstAcCode_InsertCommand" OnDeleteCommand="rggstAcCode_DeleteCommand"
OnUpdateCommand="rggstAcCode_UpdateCommand" EnableEmbeddedSkins="true" Skin="Outlook">
<mastertableview commanditemdisplay="Top" autogeneratecolumns="false" datakeynames="AccountCodeID"
insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" ShowHeadersWhenNoRecords="true">
<CommandItemSettings AddNewRecordText="New" />
<Columns>
<telerik:GridEditCommandColumn UniqueName="imagebutton1" ButtonType="ImageButton"></telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
<ItemTemplate>
<asp:Label ID="lblAcCode" Text='<%# Eval("AccountCode") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
<telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="260" DropDownWidth="310"
EnableLoadOnDemand="True" OnItemsRequested="ddlAccountCode_ItemsRequested" EnableItemCaching="true"
ShowMoreResultsBox="True" EnableVirtualScrolling="true" AllowCustomText="true" MarkFirstMatch="true"
Filter="Contains" HighlightTemplatedItems="true" CausesValidation="true" AppendDataBoundItems="true"
DataTextField="AccountDescription" DataValueField="AccountCodeID"
ShowDropDownOnTextboxClick="false"
OnClientDropDownOpening="OnClientDropDownOpening" OnClientItemsRequested="OnClientItemsRequested">
</telerik:RadComboBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" OnClientClick="ButtonClicked()" UseSubmitBehavior="true" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
//Other columns
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
<PagerStyle AlwaysVisible="True" PageSizeControlType="RadComboBox" />
</mastertableview>
</telerik:RadGrid>
<%--</telerik:RadAjaxPanel>--%>
</telerik:RadPageView>
</telerik:RadMultiPage>
C#代码:
protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
Session["Text"] = e.Text;
Session["NumberOfItems"] = e.NumberOfItems;
RadComboBox combo = (RadComboBox)sender;
combo.ShowDropDownOnTextboxClick = false;
combo.Items.Clear();
combo.HighlightTemplatedItems = true;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
GridEditableItem editedItem = (sender as Button).NamingContainer as GridEditableItem;
RadComboBox combo = (RadComboBox)editedItem.FindControl("ddlAccountCode");
//clear the previous items on every new search
combo.Items.Clear();
combo.OpenDropDownOnLoad = true; // opens dropdown of RadComboBox on button click
combo.HighlightTemplatedItems = true; // to highlight the searched text
//Code related to search in RadComboBox
combo.DataBind();
}
catch (Exception ex)
{
}
}
请告诉我如何解决这 2 个问题。请回复。
提前致谢。
抱歉,我无法在我的环境中复制您的问题....
这是我的代码使用
.aspx
<telerik:RadGrid ID="RGGSTAcCode" runat="server" AutoGenerateColumns="false"
ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true"
AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
OnNeedDataSource="rggstAcCode_NeedDataSource">
<MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false"
InsertItemPageIndexAction="ShowItemOnCurrentPage" ShowFooter="True" ShowHeadersWhenNoRecords="true">
<CommandItemSettings AddNewRecordText="New" />
<Columns>
<telerik:GridEditCommandColumn UniqueName="imagebutton1" ButtonType="ImageButton"></telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
<ItemTemplate>
<asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
<telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="260" DropDownWidth="310"
EnableItemCaching="true" ShowMoreResultsBox="True" EnableVirtualScrolling="true" AllowCustomText="true"
MarkFirstMatch="true" Filter="Contains" HighlightTemplatedItems="true" CausesValidation="true"
AppendDataBoundItems="true" ShowDropDownOnTextboxClick="false" OnItemsRequested="ddlAccountCode_ItemsRequested">
</telerik:RadComboBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
<PagerStyle AlwaysVisible="True" PageSizeControlType="RadComboBox" />
</MasterTableView>
</telerik:RadGrid>
.cs
protected void Page_Load(object sender, EventArgs e)
{
// Check
if (!IsPostBack)
{
// Variable
DataTable dt = new DataTable();
dt.Columns.Add("AccountCode");
dt.Columns.Add("AccountDescription");
for (int i = 0; i < 10; i++) dt.Rows.Add("AccountCode" + i, "AccountDescription" + i);
ViewState["data"] = dt;
// Bind
RGGSTAcCode.DataSource = dt;
RGGSTAcCode.DataBind();
// Dispose
dt.Dispose();
}
}
protected void rggstAcCode_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
RGGSTAcCode.DataSource = ViewState["data"] as DataTable;
}
protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
Session["Text"] = e.Text;
Session["NumberOfItems"] = e.NumberOfItems;
RadComboBox combo = (RadComboBox)sender;
combo.ShowDropDownOnTextboxClick = false;
combo.Items.Clear();
combo.HighlightTemplatedItems = true;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
GridEditableItem editedItem = (sender as Button).NamingContainer as GridEditableItem;
RadComboBox combo = (RadComboBox)editedItem.FindControl("ddlAccountCode");
//clear the previous items on every new search
combo.Items.Clear();
combo.OpenDropDownOnLoad = true; // opens dropdown of RadComboBox on button click
combo.HighlightTemplatedItems = true; // to highlight the searched text
//Code related to search in RadComboBox
combo.DataSource = ViewState["data"] as DataTable;
combo.DataTextField = "AccountCode";
combo.DataValueField = "AccountCode";
combo.DataBind();
}
catch (Exception ex)
{
}
}
结果如下
我删除了 RadAjaxPanel
并使用了 asp.net UpdatePanel
并且问题已解决,因为页面不会 post 返回按钮点击和以上行为永远不会发生。但是我不知道为什么当我不把 RadGrid
放在 RadAjaxPanel
或 UpdatePanel
.
中时它会产生问题
有一个 RadGrid
,其中包含 RadcomboBox
以及旁边的 button
。
当用户键入内容并单击按钮时,数据绑定到 RadComboBox
与键入文本相关并显示在 DropdownList
.
但是这个 DropdownList
出现在 RadcomboBox
的下方很远,这会扰乱页面的外观。请参阅随附的问题快照。
我尝试设置 ExpandDirection="Down"
属性 但没有成功。
我还尝试设置 EnableScreenBoundaryDetection="false"
,这坚持
下拉列表在页面底部,所以当我滚动页面时,下拉列表总是停留在底部并且它也随着页面滚动。
此外,我设置了 HighlightTemplatedItems="true"
但它根本不起作用。
编辑: HTML代码:
<telerik:RadMultiPage ID="RadMultiPage6" runat="server" SelectedIndex="0" Width="100%">
<telerik:RadPageView ID="RadPageView5" runat="server" Width="100%">
<%--<telerik:RadAjaxPanel ID="RadAjaxPanel5" runat="server">--%>
<telerik:RadGrid ID="RGGSTAcCode" runat="server" AutoGenerateColumns="false"
ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true"
AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
OnNeedDataSource= "rggstAcCode_NeedDataSource" OnItemDataBound="rggstAcCode_ItemDataBound"
OnInsertCommand="rggstAcCode_InsertCommand" OnDeleteCommand="rggstAcCode_DeleteCommand"
OnUpdateCommand="rggstAcCode_UpdateCommand" EnableEmbeddedSkins="true" Skin="Outlook">
<mastertableview commanditemdisplay="Top" autogeneratecolumns="false" datakeynames="AccountCodeID"
insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" ShowHeadersWhenNoRecords="true">
<CommandItemSettings AddNewRecordText="New" />
<Columns>
<telerik:GridEditCommandColumn UniqueName="imagebutton1" ButtonType="ImageButton"></telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
<ItemTemplate>
<asp:Label ID="lblAcCode" Text='<%# Eval("AccountCode") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
<telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="260" DropDownWidth="310"
EnableLoadOnDemand="True" OnItemsRequested="ddlAccountCode_ItemsRequested" EnableItemCaching="true"
ShowMoreResultsBox="True" EnableVirtualScrolling="true" AllowCustomText="true" MarkFirstMatch="true"
Filter="Contains" HighlightTemplatedItems="true" CausesValidation="true" AppendDataBoundItems="true"
DataTextField="AccountDescription" DataValueField="AccountCodeID"
ShowDropDownOnTextboxClick="false"
OnClientDropDownOpening="OnClientDropDownOpening" OnClientItemsRequested="OnClientItemsRequested">
</telerik:RadComboBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" OnClientClick="ButtonClicked()" UseSubmitBehavior="true" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
//Other columns
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
<PagerStyle AlwaysVisible="True" PageSizeControlType="RadComboBox" />
</mastertableview>
</telerik:RadGrid>
<%--</telerik:RadAjaxPanel>--%>
</telerik:RadPageView>
</telerik:RadMultiPage>
C#代码:
protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
Session["Text"] = e.Text;
Session["NumberOfItems"] = e.NumberOfItems;
RadComboBox combo = (RadComboBox)sender;
combo.ShowDropDownOnTextboxClick = false;
combo.Items.Clear();
combo.HighlightTemplatedItems = true;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
GridEditableItem editedItem = (sender as Button).NamingContainer as GridEditableItem;
RadComboBox combo = (RadComboBox)editedItem.FindControl("ddlAccountCode");
//clear the previous items on every new search
combo.Items.Clear();
combo.OpenDropDownOnLoad = true; // opens dropdown of RadComboBox on button click
combo.HighlightTemplatedItems = true; // to highlight the searched text
//Code related to search in RadComboBox
combo.DataBind();
}
catch (Exception ex)
{
}
}
请告诉我如何解决这 2 个问题。请回复。
提前致谢。
抱歉,我无法在我的环境中复制您的问题....
这是我的代码使用
.aspx
<telerik:RadGrid ID="RGGSTAcCode" runat="server" AutoGenerateColumns="false"
ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true"
AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
OnNeedDataSource="rggstAcCode_NeedDataSource">
<MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false"
InsertItemPageIndexAction="ShowItemOnCurrentPage" ShowFooter="True" ShowHeadersWhenNoRecords="true">
<CommandItemSettings AddNewRecordText="New" />
<Columns>
<telerik:GridEditCommandColumn UniqueName="imagebutton1" ButtonType="ImageButton"></telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
<ItemTemplate>
<asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
<telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="260" DropDownWidth="310"
EnableItemCaching="true" ShowMoreResultsBox="True" EnableVirtualScrolling="true" AllowCustomText="true"
MarkFirstMatch="true" Filter="Contains" HighlightTemplatedItems="true" CausesValidation="true"
AppendDataBoundItems="true" ShowDropDownOnTextboxClick="false" OnItemsRequested="ddlAccountCode_ItemsRequested">
</telerik:RadComboBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
<PagerStyle AlwaysVisible="True" PageSizeControlType="RadComboBox" />
</MasterTableView>
</telerik:RadGrid>
.cs
protected void Page_Load(object sender, EventArgs e)
{
// Check
if (!IsPostBack)
{
// Variable
DataTable dt = new DataTable();
dt.Columns.Add("AccountCode");
dt.Columns.Add("AccountDescription");
for (int i = 0; i < 10; i++) dt.Rows.Add("AccountCode" + i, "AccountDescription" + i);
ViewState["data"] = dt;
// Bind
RGGSTAcCode.DataSource = dt;
RGGSTAcCode.DataBind();
// Dispose
dt.Dispose();
}
}
protected void rggstAcCode_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
RGGSTAcCode.DataSource = ViewState["data"] as DataTable;
}
protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
Session["Text"] = e.Text;
Session["NumberOfItems"] = e.NumberOfItems;
RadComboBox combo = (RadComboBox)sender;
combo.ShowDropDownOnTextboxClick = false;
combo.Items.Clear();
combo.HighlightTemplatedItems = true;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
GridEditableItem editedItem = (sender as Button).NamingContainer as GridEditableItem;
RadComboBox combo = (RadComboBox)editedItem.FindControl("ddlAccountCode");
//clear the previous items on every new search
combo.Items.Clear();
combo.OpenDropDownOnLoad = true; // opens dropdown of RadComboBox on button click
combo.HighlightTemplatedItems = true; // to highlight the searched text
//Code related to search in RadComboBox
combo.DataSource = ViewState["data"] as DataTable;
combo.DataTextField = "AccountCode";
combo.DataValueField = "AccountCode";
combo.DataBind();
}
catch (Exception ex)
{
}
}
结果如下
我删除了 RadAjaxPanel
并使用了 asp.net UpdatePanel
并且问题已解决,因为页面不会 post 返回按钮点击和以上行为永远不会发生。但是我不知道为什么当我不把 RadGrid
放在 RadAjaxPanel
或 UpdatePanel
.