我有一个用于编辑数据的“ RadGrid”。
我启用了过滤。
我使用“ RadInputManager”执行验证。
当我尝试更新更改时,“ RadInputManager”也在验证“ TextBox”过滤器。
我该如何解决?
我添加代码“ aspx”以显示示例:
<telerik:RadAjaxManager runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelCssClass="" />
<telerik:AjaxUpdatedControl ControlID="RadInputManager1" UpdatePanelCssClass="" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
</asp:ScriptReference>
</Scripts>
</telerik:RadScriptManager>
<telerik:RadInputManager ID="RadInputManager1" runat="server">
<telerik:TextBoxSetting InitializeOnClient="False" ErrorMessage="Required!" Validation-IsRequired="True" Validation-ValidateOnEvent="Submit">
<TargetControls>
<telerik:TargetInput ControlID="RadGrid1" />
</TargetControls>
</telerik:TextBoxSetting>
</telerik:RadInputManager>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateEditColumn="True" CellSpacing="0" DataSourceID="LinqDataSource1" EnableHeaderContextFilterMenu="True" EnableHeaderContextMenu="True" GridLines="None">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="RolId" DataSourceID="LinqDataSource1" EditMode="InPlace">
<Columns>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" UniqueName="Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" UniqueName="Description">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="WebApplication1.DataClasses1DataContext" EntityTypeName="" TableName="Rol">
</asp:LinqDataSource>
谢谢,
德尔维斯
最佳答案
看起来您可以使用RadGrid ItemCreated事件动态地将“验证行为”添加到绑定控件中,并声明Telerik:TextBoxSetting
而不指定目标控件。
前端(标记)
<telerik:RadInputManager ID="RadInputManager1" runat="server">
<telerik:TextBoxSetting BehaviorID="TextBoxBehavior1" InitializeOnClient="False" ErrorMessage="Required!" Validation-IsRequired="True" Validation-ValidateOnEvent="Submit">
</telerik:TextBoxSetting>
</telerik:RadInputManager>
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemCreated="RadGrid1_ItemCreated" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateEditColumn="True" CellSpacing="0" DataSourceID="LinqDataSource1" EnableHeaderContextFilterMenu="True" EnableHeaderContextMenu="True" GridLines="None">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="RolId" DataSourceID="LinqDataSource1" EditMode="InPlace">
<Columns>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" UniqueName="Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" UniqueName="Description">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
代码隐藏
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditFormItem editedItem = e.Item as GridEditFormItem;
TextBoxSetting inputSettings = (DateInputSetting)RadInputManager1.GetSettingByBehaviorID("TextBoxBehavior1");
RadTextBox tbName = editedItem.FindControl("tbName") as RadTextBox;
RadTextBox tbDescription = editedItem.FindControl("tbDescription") as RadTextBox;
inputSettings.TargetControls.Add(new TargetInput(tbName.UniqueID, true));
inputSettings.TargetControls.Add(new TargetInput(tbDescription.UniqueID, true));
}
}
请注意,
tbName
和tbDescription
可能不存在。当然,每个数据字段都将创建一个文本框,但是如果将列保留为telerik:GridBoundColumns ...,则必须发现控件的生成名称是什么。替代方法是使用GridTemplateColumn。备用列(标记:RadGrid> MasterTableView>列)
<telerik:GridTemplateColumn HeaderText="Name" SortExpression="Name">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="tbName" Width="60px" runat="server" Text='<%# Bind("Name")%>'>
</telerik:RadTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Description" SortExpression="Description">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Description") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox Width="245px" ID="tbDescription" runat="server" TextMode="MultiLine" Resize="Both" Text='<%# Bind("Description")%>' EmptyMessage="type description">
</telerik:RadTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
让我知道,这应该对您有用。.我还没有进行测试。
关于c# - Telerik RadInputManager与RadGrid集成,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28073051/