Asp.net 如何将RadNumericTextBox的最小值设置为正在编辑的值

Asp.net 如何将RadNumericTextBox的最小值设置为正在编辑的值,asp.net,.net,grid,telerik,edit,Asp.net,.net,Grid,Telerik,Edit,我在RadGrid中的GridTemplate列中有一个RadnumericTextBox,我希望能够将MinValue属性设置为正在编辑的初始值,然后用户才能更改它。其思想是,用户可以继续增加值,但一旦保存,就不能减少值 我一直在尝试提出一些服务器端的解决方案,但从我可以看出,网格模板列不是网格渲染的一部分 <telerik:RadGrid ID="StudentGrid" AutoGenerateColumns="false" AllowFilteringByColumn="True"

我在RadGrid中的GridTemplate列中有一个RadnumericTextBox,我希望能够将MinValue属性设置为正在编辑的初始值,然后用户才能更改它。其思想是,用户可以继续增加值,但一旦保存,就不能减少值

我一直在尝试提出一些服务器端的解决方案,但从我可以看出,网格模板列不是网格渲染的一部分

<telerik:RadGrid ID="StudentGrid" AutoGenerateColumns="false" AllowFilteringByColumn="True" AllowSorting="True" AllowPaging="True"
            OnNeedDataSource="StudentGrid_OnNeedDataSource"
            runat="server">
    <telerik:GridTemplateColumn AllowFiltering="False" HeaderStyle-Width="25px" DataField="Sunday"
          HeaderText="Sunday" UniqueName="SundayColumn">
       <EditItemTemplate>
          <telerik:RadNumericTextBox ID="editTextBox" Type="Number" MinValue="0" MaxValue="9"
                DisplayText='<%# Bind("Sunday") %>' AllowOutOfRangeAutoCorrect="true" runat="server">
             <NumberFormat GroupSeparator="" DecimalDigits="0"></NumberFormat>
          </telerik:RadNumericTextBox>
       </EditItemTemplate>
       <ItemTemplate>
          <%# DataBinder.Eval(Container.DataItem, "Sunday") %>
       </ItemTemplate>
    </telerik:GridTemplateColumn>
</telerik:RadGrid>


更新:网格模板在页面上呈现一次,并重新用于该列中的每个单元格。它将被重新定位并具体化到正在编辑的任何单元格的顶部。由于未绑定到任何特定单元格,因此在呈现页面之前,没有与正在编辑的单元格相关联的信息。有关我的客户端解决方案,请参见下文。

解决方案是截获客户端OnCellSelecting grid事件以及OnFocus/OnBlur RadNumerictextBox事件

<telerik:RadGrid ID="StudentGrid" AutoGenerateColumns="false" AllowFilteringByColumn="True" AllowSorting="True" AllowPaging="True"
    OnNeedDataSource="StudentGrid_OnNeedDataSource"
    runat="server">
    <ClientSettings>
        <Selecting CellSelectionMode="SingleCell"></Selecting>
        <ClientEvents OnCellSelecting="StudentGrid_OnCellSelecting"/>
    </ClientSettings>
    <telerik:GridTemplateColumn AllowFiltering="False" HeaderStyle-Width="25px" DataField="Sunday"
          HeaderText="Sunday" UniqueName="SundayColumn">
       <EditItemTemplate>
          <telerik:RadNumericTextBox ID="editTextBox" Type="Number" MinValue="0" MaxValue="9"
                DisplayText='<%# Bind("Sunday") %>' AllowOutOfRangeAutoCorrect="true" runat="server">
             <NumberFormat GroupSeparator="" DecimalDigits="0"></NumberFormat>
             <ClientEvents OnFocus="onEditTextBoxFocus" OnBlur="onEditTextBoxBlur"></ClientEvents>
          </telerik:RadNumericTextBox>
       </EditItemTemplate>
       <ItemTemplate>
          <%# DataBinder.Eval(Container.DataItem, "Sunday") %>
       </ItemTemplate>
    </telerik:GridTemplateColumn>
</telerik:RadGrid>

然后添加这些javascript事件处理程序

<script type="text/javascript">
    function onEditTextBoxFocus(sender, eventArgs)
    {
        // sender is the RadNumericTextBox and does not contain any information
        // about the grid row so we have to look at it's parent to get the
        // grid row cells
        var cells = sender.get_parent().get_element().cells;
        // Switch from Telerik to jQuery to locate selected cell and get it's initial value
        var selectedCell = $(cells).filter('.rgSelectedCell');
        var initialValue = selectedCell.attr("InitialValue");
        sender.set_minValue(initialValue);
    }

    function onEditTextBoxBlur(sender, eventArgs)
    {
        // Have to reset this value because it's interfering with
        //validation on next cell being edited
        sender.set_minValue(0);
    }

    function StudentGrid_OnCellSelecting(sender, eventArgs)
    {
        // Get the grid cell being selected
        var columnName = eventArgs.get_column().get_uniqueName();
        var data = eventArgs.get_gridDataItem();
        var cell = data.get_cell(columnName);
        var initialValue = cell.getAttribute("InitialValue");
        // Set inital value if it doesn't already exist
        if (initialValue == null)
        {
            var cellValue = cell.innerText.charAt(0);
            if (cellValue == '') cellValue = 0;
            // Set an InitialValue attribute in the cell about to be edited
            // This will be picked up by the RadNumericTextBox when it gets focus (see above)
            cell.setAttribute("InitialValue", cellValue);
        }
    }
</script>

函数onEditTextBoxFocus(发送方、事件参数)
{
//发件人是RadNumericTextBox,不包含任何信息
//关于网格行,因此我们必须查看它的父级才能获得
//网格行单元格
var cells=sender.get\u parent().get\u element().cells;
//从Telerik切换到jQuery以定位所选单元格并获取其初始值
var selectedCell=$(cells.filter('.rgSelectedCell');
var initialValue=selectedCell.attr(“initialValue”);
发送方。设置最小值(初始值);
}
函数onEditTextBoxBlur(发送方、事件参数)
{
//必须重置此值,因为它会干扰
//正在编辑的下一个单元格的验证
发送方。设置_最小值(0);
}
函数StudentGrid\u oncell选择(发送方、事件参数)
{
//获取要选择的网格单元
var columnName=eventArgs.get_column().get_uniqueName();
var data=eventArgs.get_gridDataItem();
var cell=data.get_cell(columnName);
var initialValue=cell.getAttribute(“initialValue”);
//如果初始值不存在,则设置初始值
if(initialValue==null)
{
var cellValue=cell.innerText.charAt(0);
如果(cellValue='')cellValue=0;
//在要编辑的单元格中设置InitialValue属性
//当RadNumericTextBox获得焦点时,它将被拾取(见上文)
cell.setAttribute(“InitialValue”,cellValue);
}
}
OnCellSelecting事件处理程序(首先)在单元格选择上激发并捕获单元格的初始值,然后再开始编辑,并将其存储在网格单元格的InitialValue属性中。这是必需的,因为相同的RadNumericTextBox用于编辑使用网格模板的每个单元格


稍后,当RadNumerictextBox获得焦点时,将从网格单元属性检索初始值,并将其应用于RadNumerictextBox的最小值。当RadNumericTextBox失去焦点时,需要将MinValue重置为0,因为它似乎会在编辑的下一个单元格上进行验证。

Roland,这与此无关。请