gpt4 book ai didi

c# - Telerik RadInputManager 与 RadGrid 集成

转载 作者:行者123 更新时间:2023-11-30 17:45:15 27 4
gpt4 key购买 nike

我有一个用于编辑数据的“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 事件动态地将验证行为添加到绑定(bind)控件,并声明 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));
}
}

注意tbNametbDescription 很可能不存在。当然,每个数据字段都创建了一个文本框,但如果您将列保留为 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com