This is a migrated thread and some comments may be shown as answers.

setting IsInEdit Mode = false through RadGrid1.MasterTableView.ClearEditItems()

13 Answers 228 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nik
Top achievements
Rank 1
Nik asked on 25 Sep 2010, 12:02 AM
Hey I am trying to remove the line after I am adding a new record into the RadGrid
I am writing following code into the RadGrid_InsertCommand for that.

grdLidEffectiveDateRanges.MasterTableView.ClearEditItems();

Same thing is working for me into the RadGrid_UpdateCommand call,

Can anyone help me out what is the method call to clear the line after Insertion of a new row?

Thanks,
Nikunj Patel

13 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Sep 2010, 06:04 AM
Hello Nikunj,

I guess you are performing the insert/update operation manually and you want to close the insert form after insertion. If so check whether you have set AllowAutomaticInserts property to true. And set it as false to solve this issue.


Thanks,
Princy.
0
Nik
Top achievements
Rank 1
answered on 27 Sep 2010, 08:00 PM
Thanks for the response Princy, But that did not workout for me,

My need is once user has Added a new row into the grid or user has updated an existing row, after specific operetion performed the grid add mode or edit mode should be removed (e.g. data entry portion),
Please see my code below. and suggest me If i am missing something.

<

 

 

telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanelForDateRanges" runat="server" />

 

 

 

<telerik:RadGrid ID="grdLidEffectiveDateRanges"

 

 

 

    AllowSorting="True" AllowPaging="True" EnableAjaxSkinRendering="True"

 

 

 

    GridLines="Both" PageSize="5" CellPadding="0" ShowStatusBar="true"

 

 

 

    Height="205px" Skin="Web20" Width="912px" runat="server"

 

 

 

    AllowAutomaticInserts="false" AllowAutomaticUpdates="false"

 

 

 

    OnNeedDataSource="grdLidEffectiveDateRanges_NeedDataSource"

 

 

 

    OnInsertCommand="grdLidEffectiveDateRanges_InsertCommand"

 

 

 

    OnUpdateCommand="grdLidEffectiveDateRanges_UpdateCommand">

 

 

 

    <ClientSettings EnablePostBackOnRowClick="true">

 

 

 

        <Scrolling AllowScroll="true" UseStaticHeaders="true"/>

 

 

 

    </ClientSettings>

 

 

 

    <MasterTableView CommandItemDisplay="Top" EditMode="InPlace" Width="100%" AllowMultiColumnSorting="True" HorizontalAlign="NotSet"

 

 

 

DataKeyNames="StartDate,EndDate,Id" AutoGenerateColumns="False">

 

 

 

<Columns>

 

 

 

<telerik:GridDateTimeColumn DataField="StartDate" HeaderText="Effective Date" UniqueName="StartDate" DataFormatString="{0:d}"><ItemStyle Width="307px" />

 

 

 

</telerik:GridDateTimeColumn>

 

 

 

<telerik:GridDateTimeColumn DataField="EndDate" HeaderText="End Date" UniqueName="EndDate" DataFormatString="{0:d}"><ItemStyle Width="307px" />

 

 

 

</telerik:GridDateTimeColumn>

 

 

 

<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderText="Action" >

 

 

 

<ItemStyle Width="100px" />

 

 

 

</telerik:GridEditCommandColumn>

 

 

 

</Columns>

 

 

 

</MasterTableView>

 

 

 

</telerik:RadGrid>

 

0
Marin
Telerik team
answered on 29 Sep 2010, 03:18 PM
Hi Nikunj,

To put the RadGrid back in regular mode please try the following: after the desired specific operation set:

grdLidEffectiveDateRanges.MasterTableView.IsItemInserted = false;

Note that the data has to be already saved in the database, otherwise the changes will be discarded. For additional information on this subject please refer to the following article.
Hope this helps.

All the best,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nik
Top achievements
Rank 1
answered on 09 Oct 2010, 07:15 PM
Princy,

Thanks for the response, appreciated.
I have another question,
In Telerik Grid, I have a following column as a dates.

<

 

 

telerik:GridDateTimeColumn DataField="StartDate" HeaderText="Effective Date" UniqueName="StartDate" DataFormatString="{0:d}" MaxDate="12-12-2999" MinDate="1-1-1970">

 

 

 

<ItemStyle Width="307px" />

 

 

 

</telerik:GridDateTimeColumn>

 


I am not able to display/edit or update this dates inside the grid.
What is the Min/Max date limit for this control.
I am expecting above dates defined in the control to be workout inside the Telerik Grid.

Thanks,
Nikunj.
0
Marin
Telerik team
answered on 11 Oct 2010, 03:15 PM
Hello Nikunj,

The RadGrid does not have any specific limitations in handling the date format. It depends on what kind of dates your data source can handle (e.g. for sql server dates must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.). Are you sure all of the dates that you are trying to display/edit are within the specified range (1970-2999)? I tested your code and it is working on my side. If the problem persists, a detailed description of the error that occurs will be apreciated in order to provide additional help.

Greetings,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nik
Top achievements
Rank 1
answered on 15 Oct 2010, 12:10 AM

Hey,

I have a two DateTimeColumn in my RadGrid. (Start Date ---- End Date--- Edit Button)
I want to put validation on Start Date & End Date , I want to compare that the date selected in "EndDate" should not be less than the date selected in "StartDate".

 

<

 

 

div class="oliver-edit-body-content oliver-edit-body-grid-content">

 

 

 

 

 

 

 

<telerik:RadGrid ID="grdLidEffectiveDateRanges" AllowSorting="True" AllowPaging="True"

 

 

 

 

 

 

 

GridLines="Both" PageSize="5" CellPadding="0" Height="230px" Skin="Web20" Width="912px"

 

 

 

 

 

 

 

ShowStatusBar="true" EnabledAJAX="True" runat="server" AllowAutomaticInserts="false"

 

 

 

 

 

 

 

AllowAutomaticUpdates="false" OnItemCreated="grdLidEffectiveDateRanges_ItemCreated"

 

 

 

 

 

 

 

OnNeedDataSource="grdLidEffectiveDateRanges_NeedDataSource" OnInsertCommand="grdLidEffectiveDateRanges_InsertCommand"

 

 

 

 

 

 

 

OnUpdateCommand="grdLidEffectiveDateRanges_UpdateCommand">

 

 

 

 

 

 

 

<ClientSettings>

 

 

 

 

 

 

 

<Scrolling AllowScroll="true" UseStaticHeaders="true" />

 

 

 

 

 

 

 

</ClientSettings>

 

 

 

 

 

 

 

<MasterTableView CommandItemDisplay="Top" EditMode="InPlace" Width="100%" AllowMultiColumnSorting="True"

 

 

 

 

 

 

 

HorizontalAlign="NotSet" DataKeyNames="StartDate,EndDate,Id" AutoGenerateColumns="False">

 

 

 

 

 

 

 

<Columns>

 

 

 

 

 

 

 

<telerik:GridDateTimeColumn DataField="StartDate" HeaderText="Effective Date" UniqueName="StartDate"

 

 

 

 

 

 

 

DataFormatString="{0:d}" MinDate="1-1-1969" MaxDate="12-31-9999">

 

 

 

 

 

 

 

<ItemStyle Width="307px" />

 

 

 

 

 

 

 

</telerik:GridDateTimeColumn>

 

 

 

 

 

 

 

<telerik:GridDateTimeColumn DataField="EndDate" HeaderText="End Date" UniqueName="EndDate"

 

 

 

 

 

 

 

DataFormatString="{0:d}" MinDate="1-1-1969" MaxDate="12-31-9999">

 

 

 

 

 

 

 

<ItemStyle Width="307px" />

 

 

 

 

 

 

 

</telerik:GridDateTimeColumn>

 

 

 

 

 

 

 

<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderText="Action">

 

 

 

 

 

 

 

<ItemStyle Width="100px" />

 

 

 

 

 

 

 

</telerik:GridEditCommandColumn>

 

 

 

 

 

 

 

</Columns>

 

 

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

 

 

</telerik:RadGrid>

 

 

 

 

 

 

 

</div>

 

0
Marin
Telerik team
answered on 15 Oct 2010, 01:48 PM
Hello Nikunj,

You can add validation to the DateTimeColumn in the following way:
You wire the ItemCreated event for the grid and add programatically the desired validators there.

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            GridDateTimeColumnEditor editorFinishDate = (GridDateTimeColumnEditor)item.EditManager.GetColumnEditor("FinishDate");
            GridDateTimeColumnEditor editorStartDate = (GridDateTimeColumnEditor)item.EditManager.GetColumnEditor("StartDate");
  
            TableCell cellFinishDate = (TableCell)editorFinishDate.PickerControl.Parent;
  
            CompareValidator validatorFinishDate = new CompareValidator();
            validatorFinishDate.ControlToValidate = editorFinishDate.PickerControl.ID;
            validatorFinishDate.ControlToCompare = editorStartDate.PickerControl.ID;
            validatorFinishDate.Operator = ValidationCompareOperator.GreaterThan;
            validatorFinishDate.ErrorMessage = "*";
            validatorFinishDate.ToolTip = "finish date should be greater than start date";
            cellFinishDate.Controls.Add(validatorFinishDate);
  
            TableCell cellStartDate = (TableCell)editorStartDate.PickerControl.Parent;
  
            CompareValidator validatorStartDate = new CompareValidator();
            validatorStartDate.ControlToValidate = editorStartDate.PickerControl.ID;
            validatorStartDate.ControlToCompare = editorFinishDate.PickerControl.ID;
            validatorStartDate.Operator = ValidationCompareOperator.LessThan;
            validatorStartDate.ToolTip = "start date should be less than finish date";
            validatorStartDate.ErrorMessage = "*";
            cellStartDate.Controls.Add(validatorStartDate);
        }
  
    }
and in the markup:
<Columns>
            <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
                //...
                <telerik:GridDateTimeColumn ColumnEditorID="FinishDateColumnEditor" DataField="FinishDate" HeaderText="FinishDate" SortExpression="FinishDate"
                    UniqueName="FinishDate" DataType="System.DateTime">
                </telerik:GridDateTimeColumn>
                <telerik:GridDateTimeColumn DataField="StartDate" ColumnEditorID="StartDateColumnEditor" HeaderText="StartDate" SortExpression="StartDate"
                    UniqueName="StartDate" DataType="System.DateTime">
                </telerik:GridDateTimeColumn>
            </Columns>
</MasterTableView>
//...
<telerik:GridDateTimeColumnEditor ID="StartDateColumnEditor" runat="server"></telerik:GridDateTimeColumnEditor>
    <telerik:GridDateTimeColumnEditor ID="FinishDateColumnEditor" runat="server"></telerik:GridDateTimeColumnEditor>

You can find out addiotional information here:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/validation/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/validation/defaultcs.aspx

Kind regards,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nik
Top achievements
Rank 1
answered on 20 Oct 2010, 03:27 PM
Telerik,

I have a two DateTimeColumn in my RadGrid. (Start Date ---- End Date--- Edit (Update/Cancel) Link Button)
I want to put validation on Start Date & End Date , I want to validate these dates should not be null. and another validation is while selecting an existing date (12/12/2999) it is giving an error/warning message with yellow color,
I would appreciate your help solving this issue.

Thanks,
Nikunj



0
Marin
Telerik team
answered on 21 Oct 2010, 01:31 PM
Hello Nikunj,

In order to validate that a specified field is not null, you should use the RequiredFieldValidator and set its desired properties. For the case with upper boundary limitation for a control, you may use the range validator. You can add those validators in the ItemCreated event for the grid as I have shown in my previous post. Here is the sample code:
GridEditableItem item = e.Item as GridEditableItem;
            GridDateTimeColumnEditor editorFinishDate = (GridDateTimeColumnEditor)item.EditManager.GetColumnEditor("FinishDate");
              
            TableCell cellFinishDate = (TableCell)editorFinishDate.PickerControl.Parent;
  
            RequiredFieldValidator reqFieldValidator = new RequiredFieldValidator();
            reqFieldValidator.ControlToValidate = editorFinishDate.PickerControl.ID;
            reqFieldValidator.ErrorMessage = "Error message with yellow color!";
            reqFieldValidator.ForeColor = Color.Yellow;
            cellFinishDate.Controls.Add(reqFieldValidator);
  
            RangeValidator rangeValidator = new RangeValidator();
            rangeValidator.ControlToValidate = editorFinishDate.PickerControl.ID;
            rangeValidator.ErrorMessage = "Error message with yellow color!";
            rangeValidator.ForeColor = Color.Yellow;
            rangeValidator.MaximumValue = "12/12/2999";
            cellFinishDate.Controls.Add(rangeValidator);

Also have in mind that the default Min and Max date for the DataPicker in the GridDateTimeColumn are respectively: 1/1/1980 and 12/31/2099. Of course you can easily change this with the MinDate and MaxDate properties of the GridDateTimeColumn. Also the inner validation of the DatePicker control is with higher priority and will be triggered before any additionally attached validators. So if you enter the date 12//31/3000 and you have set MaxDate=12/31/2999 you will see just the default error look of the DatePicker without the custom messages from the validator.

All the best,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nik
Top achievements
Rank 1
answered on 25 Oct 2010, 05:21 AM
Thanks Telerik Team for you previous response,appreciated.

I have a question on Telrik rad grid sorting facility.
I have set a a rad grid property AllowSorting="True"
But Radgrid does not sort numbers fields as it should be with normal sorting.
I am using following column within the radgrid.

<

 

 

telerik:GridBoundColumn DataField="CscCode" HeaderText="Code">

 

 

 

         <ItemStyle Width="20px" />

 

 

 

</telerik:GridBoundColumn>
and it sort the field in following way, e.g. example
125
129
13
136
14
145
while I need sorting as
13
14
125
129 ....
Am I missing any property setting to get this type of sorting?

And My second question is I have used following column in Rad grid to achive date functionality.

 

 

 

 

<telerik:GridDateTimeColumn DataField="EndDate" HeaderText="End Date" UniqueName="EndDate"

 

 

 

 

                            DataFormatString="{0:d}" MinDate="1-1-1969" MaxDate="12-31-9999">

 

 

 

 

         <ItemStyle Width="307px" />

 

 

 

 

</telerik:GridDateTimeColumn>
while I am getting this date 12/12/2999 from DB, It does allow me to display and save but at the time of editing this field it gives a warning symbol which red color font date, what is the soln. for that.
I also set rangeValidator.MaximumValue = "12/12/9999"; on item_created, stil it gives me a same error.

Thanks,
Nikunj

 

0
Marin
Telerik team
answered on 26 Oct 2010, 07:17 AM
Hi Nikunj,

The soring depends on the type of the field that comes from your database. If it is of some text type (e.g. varchar, nvarchar, text etc.) it will be sorted lexicographically (i.e.  1, 12, 124, 2, 206, 31...) in order to achieve numeric sorting the type of your field has to be a numeric type (i.e. int, decimal, float...). It all depends on the type of the CscCode field.

To limit the range of the dates that are allowed to be entered in the DateTimeColumn you only need to use the MaxData and MinDate properties of the column itself, you do not need additional range validators unless you want additional customization, like specific error text, color, etc. Here is a code snippet showing this approach:
<telerik:GridDateTimeColumn MinDate="1/1/1960" MaxDate="12/31/2999"  DataField="StartDate" HeaderText="StartDate" UniqueName="StartDate">

If you do need to use range validators, be sure to configure it properly, setting its type and limit values like in the following way:
rangeValidator.Type = ValidationDataType.Date;
rangeValidator.MinimumValue = "1/1/1960";
rangeValidator.MaximumValue = "12/31/2999";

Hope this helps.

Greetings,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nik
Top achievements
Rank 1
answered on 03 Nov 2010, 05:39 AM
Thanks Telerik Team,
Few of your tips really help, appreciated.
I also need you help on this following senario.
e.g. I have a Rad Grid controls with number of records in it and couple of the properties I have set as AllowPaging="True", PageSize="10". If Grid has more then 10 records then it displays AutoPaging control for page navigation with page size at the bottom of the Grid. If a user selects Page Size 50 to see all, and if there are less than 50 records, the paging controls disappear from bottom. The user is unable to go back to 10/20 per page. Could you please help me out in this?

Thanks in advance,
Nikunj Patel
0
Princy
Top achievements
Rank 2
answered on 03 Nov 2010, 06:28 AM
Hello Nikunj,

Try to set PagerStyle>AlwaysVisible property to true, so that the pager is always visible.

ASPX:
<MasterTableView >
    <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />

Thanks,
Princy.
Tags
Grid
Asked by
Nik
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Nik
Top achievements
Rank 1
Marin
Telerik team
Share this question
or