Radgrid Default Date in Batch Editmode

9 posts, 0 answers
  1. Rick
    Rick avatar
    8 posts
    Member since:
    Aug 2014

    Posted 20 Mar 2015 Link to this post

    I have a radgrid that is set to batch editmode with edittype of "cell"

    When I hit the addrecord button I want a date column to default to today's date.

    Anyone have an example?

    Thanks,
  2. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 25 Mar 2015 Link to this post

    Hi Rick,

    You can use the following approach to achieve this requirement:
    protected void RadGrid1_DataBinding(object sender, EventArgs e)
    {
        GridDateTimeColumn col = RadGrid1.MasterTableView.GetColumn("OrderDate") as GridDateTimeColumn;
        col.DefaultInsertValue = DateTime.Now.ToShortDateString();
    }

    Hope this helps.

    Regards,
    Eyup
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rick
    Rick avatar
    8 posts
    Member since:
    Aug 2014

    Posted 25 Mar 2015 Link to this post

    I tried your solution but it did not work.

    This is the grid when the page opens
    1
    This is the grid after I hit the 'Add new record' button.
     It is here that I want to display the current date.












  5. Rick
    Rick avatar
    8 posts
    Member since:
    Aug 2014

    Posted 25 Mar 2015 in reply to Rick Link to this post

    With gif of screen prints
  6. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 30 Mar 2015 Link to this post

    Hi Rick,

    I've created a sample RadGrid web site to demonstrate that the suggested approach works as expected. Can you please run the attached application and let me know about the result on your side?

    Regards,
    Eyup
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  7. Rick
    Rick avatar
    8 posts
    Member since:
    Aug 2014

    Posted 30 Mar 2015 Link to this post

    When I changed my column from a string template column to a datetime column it worked.

    Now my problem is that the insert to my table no longer works although my update to the same table does work.

    Here are the insert and update statements                        
    InsertCommand= " Insert into tasks (Date_Entered ,TaskType_ID , Originator_ID,Owner_ID ,Complete,Task ,Teststand_ID) values(@Date_Entered ,@Tasktype_ID,@Originator_ID, @Owner_ID,0,@Task,@teststand_ID)" 
     
    UpdateCommand=" Update tasks set Date_Entered= @Date_Entered ,TaskType_ID =@TaskType_ID , Originator_ID =@Originator_ID,Owner_ID = @Owner_ID ,Complete = @Complete,Task=@Task where Task_ID =@Task_ID">












  8. Rick
    Rick avatar
    8 posts
    Member since:
    Aug 2014

    Posted 30 Mar 2015 in reply to Rick Link to this post

    Here are my params...
                            <InsertParameters>
                                <asp:Parameter Name="Tasktype_ID" Type="Int32" />
                                <asp:Parameter Name="Date_Entered" Type="Datetime" />
                                <asp:Parameter Name="Originator_ID" Type="Int32" />
                                <asp:Parameter Name="Owner_ID" Type="Int32" />
                                <asp:Parameter Name="Task" Type="String" />
                                <asp:ControlParameter ControlID="ComboPLCTestStand" DefaultValue="3" Name="teststand_ID" PropertyName="SelectedValue" />
                            </InsertParameters>
                             <UpdateParameters>
                               <asp:Parameter Name="Tasktype_ID" Type="Int32" />
                                <asp:Parameter Name="Date_Entered" Type="Datetime" />
                                <asp:Parameter Name="Originator_ID" Type="Int32" />
                                <asp:Parameter Name="Owner_ID" Type="Int32" />
                                <asp:Parameter Name="Task" Type="String" />
                                <asp:Parameter Name="Task_ID"  Type="Int32"/> 
                                <asp:Parameter Name="Complete" type="Boolean"/> 
                            </UpdateParameters>
  9. Rick
    Rick avatar
    8 posts
    Member since:
    Aug 2014

    Posted 30 Mar 2015 in reply to Rick Link to this post

    This insert with hardcoded date works....

    InsertCommand= " Insert into tasks (Date_Entered ,TaskType_ID , Originator_ID,Owner_ID ,Complete,Task ,Teststand_ID) values('03/25/2015' ,@Tasktype_ID,@Originator_ID, @Owner_ID,0,@Task,@teststand_ID)" 
  10. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 02 Apr 2015 Link to this post

    Hi Rick,

    Could you verify whether the field is of type DateTime in your database? Also, does editing work with the modified configuration?

    Alternatively, you can bring back the previous column and set the default value manually using the changeCellValue method:
    http://www.telerik.com/help/aspnet-ajax/grid-batch-editing.html

    Regards,
    Eyup
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017