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

[Solved] Setting Default Values in Edit Form

8 Answers 360 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jason
Top achievements
Rank 1
Jason asked on 03 Feb 2011, 08:24 PM
I cannot find any information on how to modify the edit form (inline, popup or form). Our model contains three date fields, and the form must set a default date for one field (today's date) and then set a date +30 in the second field and the date +60 in the third field. How is this accomplished through your Grid components?

8 Answers, 1 is accepted

Sort by
0
dizzwave
Top achievements
Rank 1
answered on 13 Apr 2011, 07:55 PM
bump!
Hi Jason, did you ever find an answer to this? I'm wondering the same about defaults for date fields.

Thanks,
dave

edit: It looks like in the demos they use a DatePicker, which does allow you to set default values. It'd be nice to have defaults for text fields, but this will work for me for dates... 
edit again: Ok, so it looks like the DatePicker lets you set a global default -- e.g. all of the DatePickers in your application will default to today's date -- but I don't see how to set different defaults per field, as in your question. Telerik guys, is there a way to do this?
0
Lucania
Top achievements
Rank 1
answered on 20 Jul 2011, 06:12 AM
I am also interested if there is a way to do this.

ROSCO
0
Atanas Korchev
Telerik team
answered on 20 Jul 2011, 07:16 AM
Hi,

 If you want to set default values for new records you should use the DefaultDataItem setting:

.Editable(editing => editing.DefaultDataItem(new SomeType
            {
                Property1 = "",
                Property2 = 20
            }))

Regards,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Lucania
Top achievements
Rank 1
answered on 21 Jul 2011, 12:24 AM
Hi Atanas,

That appears to be part of the MVC extensions, is it possible using webforms?

ROSCO
0
Atanas Korchev
Telerik team
answered on 21 Jul 2011, 06:47 AM
Hello Ross,

 I am not sure what you mean. This forum is for Telerik Grid for ASP.NET MVC. Are you using the same component?

Regards,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Lucania
Top achievements
Rank 1
answered on 21 Jul 2011, 07:15 AM
Apologies I found this thread with a search, and failed to notice it was in the MVC section.

ROSCO
0
Genti
Telerik team
answered on 21 Jul 2011, 01:39 PM
Hi Ross,

I am attaching a sample solution that illustrates what you are trying to achieve.
In my solution I am giving two options:

1) Define the dates in declaratively in the design page:
<telerik:GridTemplateColumn UniqueName="Date1" HeaderText="Date1">
                        <ItemTemplate>
                            <asp:Label Text='<%# Eval("StartTime") %>' runat="server" />
                        </ItemTemplate>
                        <EditItemTemplate>
                             <telerik:RadDatePicker ID="picker1" MinDate="1900/1/1" runat="server"  DbSelectedDate='<%# Bind("StartTime") %>' SelectedDate='<%# System.DateTime.Now.AddDays(2) %>' ></telerik:RadDatePicker>
                        </EditItemTemplate>
</telerik:GridTemplateColumn>

2) Or, if you need to make more complex manipulations to the dates you can modify them in the code behind(i have commented out this part in my solution)
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode == true)
    {
        (e.Item.FindControl("picker3") as RadDatePicker).SelectedDate = DateTime.Now;
        (e.Item.FindControl("picker2") as RadDatePicker).SelectedDate = DateTime.Now.AddDays(1);
        (e.Item.FindControl("picker1") as RadDatePicker).SelectedDate = DateTime.Now.AddDays(2);
    }
}

I am also attaching the dummy database table that I used for this example.

Kind regards,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Lucania
Top achievements
Rank 1
answered on 25 Jul 2011, 12:09 AM
Thanks!

ROSCO
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
dizzwave
Top achievements
Rank 1
Lucania
Top achievements
Rank 1
Atanas Korchev
Telerik team
Genti
Telerik team
Share this question
or