Rad Grid Insert Mode TextBox Issue

3 posts, 0 answers
  1. Vijay
    Vijay avatar
    29 posts
    Member since:
    Nov 2011

    Posted 10 Feb 2015 Link to this post

    I am using rad grid, when i click on add records button the grid will become into insert mode and allows me to enter respective data but in below CastSummary Textbox when I click to enter some data it is showing DatePicker and it's not allowing me to enter text. Please suggest

    Pleas see the image attached.

    My Complete .ascx code is:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="MountainVillaNursing.Residents.Test" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <div>
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="false" AllowPaging="true"
            OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCreated="RadGrid1_ItemCreated"
            OnInsertCommand="RadGrid1_InsertCommand">
            <MasterTableView DataKeyNames="CurrentDiagnosisId" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage">
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                    <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" DataField="Diagnosis" DataType="System.String" HeaderText="Diagnosis"
                        SortExpression="Diagnosis">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" DataField="ICN" DataType="System.String" HeaderText="ICD-9-Code"
                        SortExpression="ICN">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" DataField="CastSummary" DataType="System.String" HeaderText="Cast Summary"
                        SortExpression="CastSummary">
                    </telerik:GridBoundColumn>
                    <telerik:GridDateTimeColumn HeaderStyle-Font-Bold="true" DataField="StartDate" DataFormatString="{0:MM/dd/yyyy}" DataType="System.DateTime" HeaderText="StartDate"
                        SortExpression="StartDate">
                    </telerik:GridDateTimeColumn>
                    <telerik:GridDateTimeColumn HeaderStyle-Font-Bold="true" DataField="EndDate" DataFormatString="{0:MM/dd/yyyy}" DataType="System.DateTime" HeaderText="EndDate"
                        SortExpression="EndDate">
                    </telerik:GridDateTimeColumn>
                </Columns>
                <EditFormSettings>
                    <EditColumn ButtonType="ImageButton" />
                </EditFormSettings>
            </MasterTableView>
            <PagerStyle Mode="NextPrevAndNumeric" />
        </telerik:RadGrid>
        <telerik:RadInputManager runat="server" ID="RadInputManager1" Enabled="true">
            <telerik:TextBoxSetting BehaviorID="TextBoxSetting1">
            </telerik:TextBoxSetting>
            <telerik:TextBoxSetting BehaviorID="TextBoxSetting2">
            </telerik:TextBoxSetting>
            <telerik:TextBoxSetting BehaviorID="TextBoxSetting3" >
            </telerik:TextBoxSetting>
     
            <telerik:DatePickerSetting BehaviorID="DatePickerSetting1" >
            </telerik:DatePickerSetting>
            <telerik:DatePickerSetting BehaviorID="DatePickerSetting2">
            </telerik:DatePickerSetting>
        </telerik:RadInputManager>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" />
    </div>


    Code File

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    namespace MountainVillaNursing.Residents
    {
     
        public partial class Test : System.Web.UI.UserControl
        {
            MountainVillaEntities _dataContext = new MountainVillaEntities();
     
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                }
            }
     
             
            
             
     
            protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
            {
                RadGrid1.DataSource = _dataContext.spGetAllCurrentDiagnosisById(1);
     
            }
     
            protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridEditableItem && (e.Item.IsInEditMode))
                {
                    GridEditableItem editableItem = (GridEditableItem)e.Item;
                    SetupInputManager(editableItem);
                }
            }
     
            private void SetupInputManager(GridEditableItem editableItem)
            {
                // style and set ProductName column's textbox as required
                var textBox =
                    ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor("Diagnosis")).TextBoxControl;
                InputSetting inputSetting = RadInputManager1.GetSettingByBehaviorID("TextBoxSetting1");
                inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
                inputSetting.InitializeOnClient = true;
                inputSetting.Validation.IsRequired = true;
     
                textBox =
                    ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor("ICN")).TextBoxControl;
                inputSetting = RadInputManager1.GetSettingByBehaviorID("TextBoxSetting2");
                inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
                inputSetting.InitializeOnClient = true;
                inputSetting.Validation.IsRequired = true;
     
     
                textBox =
                    ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor("CastSummary")).TextBoxControl;
                inputSetting = RadInputManager1.GetSettingByBehaviorID("TextBoxSetting3");
                inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
                inputSetting.InitializeOnClient = true;
                inputSetting.Validation.IsRequired = true;
     
               var datetime =
                (GridDateTimeColumnEditor)editableItem.EditManager.GetColumnEditor("StartDate") as GridDateTimeColumnEditor;
                inputSetting = RadInputManager1.GetSettingByBehaviorID("DatePickerSetting1");
                inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
                inputSetting.InitializeOnClient = true;
                inputSetting.Validation.IsRequired = true;
     
                 datetime =
                (GridDateTimeColumnEditor)editableItem.EditManager.GetColumnEditor("EndDate") as GridDateTimeColumnEditor;
                inputSetting = RadInputManager1.GetSettingByBehaviorID("DatePickerSetting2");
                inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
                inputSetting.InitializeOnClient = true;
                inputSetting.Validation.IsRequired = true;
     
     
     
     
            }
     
            protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
            {
                var editableItem = ((GridEditableItem)e.Item);
                //create new entity
                var currentDiagnosis = new tblCurrentDiagnosi();
                //populate its properties
     
                Hashtable values = new Hashtable();
                editableItem.ExtractValues(values);
                string diagnosis = (string)values["Diagnosis"];
                string iCN = (string)values["ICN"];
                string castSummary = (string)values["CastSummary"];
                DateTime? startDate = (DateTime)values["StarDate"];
                DateTime? endDate = (DateTime)values["EndDate"];
     
     
                _dataContext.spInsertCurrentDiagnosis(diagnosis, iCN,castSummary, startDate, endDate, 1, "Test", true);
                try
                {
                    //save chanages to Db
                    _dataContext.SaveChanges();
                }
                catch (System.Exception)
                {
                }
            }
            public override void Dispose()
            {
                if (_dataContext != null)
                {
                    _dataContext.Dispose();
                }
                base.Dispose();
            }
     
        }
    }


  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 12 Feb 2015 Link to this post

    Hello Vijay,

    I have examined the provided code snippet and I have noticed that you keep using the textBox object for the date pickers as well, when you set the target controls for the RadInputManager. You need to modify the code within the SetupInputManager method with the following:
    var datetime = ((GridDateTimeColumnEditor)editableItem.EditManager.GetColumnEditor("StartDate") as GridDateTimeColumnEditor).PickerControl;
    inputSetting = RadInputManager1.GetSettingByBehaviorID("DatePickerSetting1");
    inputSetting.TargetControls.Add(new TargetInput(datetime.UniqueID, true));
    inputSetting.InitializeOnClient = true;
    inputSetting.Validation.IsRequired = true;
     
    datetime = ((GridDateTimeColumnEditor)editableItem.EditManager.GetColumnEditor("EndDate") as GridDateTimeColumnEditor).PickerControl;
    inputSetting = RadInputManager1.GetSettingByBehaviorID("DatePickerSetting2");
    inputSetting.TargetControls.Add(new TargetInput(datetime.UniqueID, true));
    inputSetting.InitializeOnClient = true;
    inputSetting.Validation.IsRequired = true;

    On a side note, when you are using GridDateTimeColumn, the generated editor for the column will be a RadDatePicker (or RadDateTimePicker), so you do not need to include the pickers in the input manager. This would be necessary if the editors were TextBox controls and you needed a Date Picker control. Having this in mind, you can safely remove the above lines from your method.

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vijay
    Vijay avatar
    29 posts
    Member since:
    Nov 2011

    Posted 12 Feb 2015 in reply to Konstantin Dikov Link to this post

    Hi Konstantin Dikov,

    Works Fantastic!

    Regards,
    Vijay
Back to Top