I have a situation similat to that in the "Copy A Record" post where I want to duplicate a records. But here is the hook, I want to take the selected record's data and populate the EditFormSettings FormTemplate without creating a new record until the user adds it. For example, I have a table with flight information for multiple users and instead of having to retpye each record I want to use the previous record data.
My initial thought was to add a button to the row and on the click expand the FormTemplate and populate the data. Is that the only way or is there an easier way. Really don't feel like wasting time on a Friday afternoon!
My initial thought was to add a button to the row and on the click expand the FormTemplate and populate the data. Is that the only way or is there an easier way. Really don't feel like wasting time on a Friday afternoon!
2 Answers, 1 is accepted
0

Michael
Top achievements
Rank 1
answered on 15 Apr 2011, 08:19 PM
Here is my RadGrid and SQLDataSource:
<
telerik:RadGrid
ID
=
"rgvwFlightInformation"
runat
=
"server"
AllowSorting
=
"True"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
AllowPaging
=
"false"
AutoGenerateColumns
=
"False"
CellSpacing
=
"0"
DataSourceID
=
"sdsFlightInformation"
EnableLinqExpressions
=
"False"
GridLines
=
"None"
Width
=
"100%"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
CommandItemDisplay
=
"Top"
DataKeyNames
=
"TravelInfoID"
DataSourceID
=
"sdsFlightInformation"
EditMode
=
"EditForms"
HorizontalAlign
=
"NotSet"
Width
=
"100%"
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
HeaderStyle-Width
=
"20px"
/>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
HeaderStyle-Width
=
"20px"
/>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"EditCommandColumn"
>
<
ItemStyle
CssClass
=
"MyImageButton"
Wrap
=
"False"
/>
</
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
DataField
=
"DisplayName"
FilterControlAltText
=
"Filter DisplayName column"
HeaderText
=
"DisplayName"
ReadOnly
=
"True"
SortExpression
=
"DisplayName"
UniqueName
=
"DisplayName"
/>
<
telerik:GridBoundColumn
DataField
=
"ProviderName"
FilterControlAltText
=
"Filter ProviderName column"
HeaderText
=
"ProviderName"
ReadOnly
=
"True"
SortExpression
=
"ProviderName"
UniqueName
=
"ProviderName"
/>
<
telerik:GridBoundColumn
DataField
=
"Confirmation"
FilterControlAltText
=
"Filter Confirmation column"
HeaderText
=
"Confirmation"
ReadOnly
=
"True"
SortExpression
=
"Confirmation"
UniqueName
=
"Confirmation"
/>
<
telerik:GridButtonColumn
ConfirmText
=
"Remove flight information?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
/>
</
telerik:GridButtonColumn
>
</
Columns
>
<
EditFormSettings
EditFormType
=
"Template"
>
<
FormTemplate
>
<
table
border
=
"0"
cellpadding
=
"2"
cellspacing
=
"0"
width
=
"100%"
>
<
tr
>
<
td
><
b
>Staff: </
b
></
td
>
<
td
>
<
asp:DropDownList
ID
=
"ddlATSStaffID"
runat
=
"server"
DataSourceID
=
"sdsATSStaffID"
DataTextField
=
"DisplayName"
DataValueField
=
"ATSStaffID"
SelectedValue='<%#Bind("ATSStaffID")%>'
SkinID="DropDownList"
Width="300"/>
</
td
>
</
tr
><
tr
>
<
td
><
b
>Airline: </
td
>
<
td
><
asp:TextBox
ID
=
"txtProviderName"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("ProviderName")%>' Width="300"/></
td
>
</
tr
><
tr
>
<
td
><
b
>Confirmation: </
td
>
<
td
><
asp:TextBox
ID
=
"txtConfirmation"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("Confirmation")%>' Width="300"/></
td
>
</
tr
><
tr
>
<
td
><
b
>Depart: </
td
>
<
td
>
<
table
border
=
"0"
cellpadding
=
"2"
cellspacing
=
"0"
>
<
tr
>
<
td
></
td
>
<
td
style
=
"text-align: center;"
><
b
>Airport</
b
></
td
>
<
td
><
b
>Date/Time</
b
></
td
>
<
td
style
=
"text-align: center;"
><
b
>Flight #</
b
></
td
>
</
tr
><
tr
>
<
td
><
b
>Depart:</
b
></
td
>
<
td
><
asp:TextBox
ID
=
"txtDepartAirport"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("sdAirport")%>' Width="35"/></
td
>
<
td
>
<
telerik:RadDateTimePicker
runat
=
"server"
ID
=
"rdtpStartDate"
DbSelectedDate='<%# Bind("StartDate") %>' Width="165">
<
TimeView
runat
=
"server"
Interval
=
"0:15:0"
Columns
=
"8"
TimeFormat
=
"h:mm:tt"
></
TimeView
>
</
telerik:RadDateTimePicker
>
</
td
>
<
td
><
asp:TextBox
ID
=
"txtDepartFlight"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("sdFlight")%>' Width="38"/></
td
>
</
tr
><
tr
>
<
td
><
b
>Arrive:</
b
></
td
>
<
td
><
asp:TextBox
ID
=
"txtArriveAirport"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("sd2Airport")%>' Width="35"/></
td
>
<
td
>
<
telerik:RadDateTimePicker
runat
=
"server"
ID
=
"rdtpsd2StartDate"
DbSelectedDate='<%# Bind("sd2StartDate") %>' Width="165">
<
TimeView
runat
=
"server"
Interval
=
"0:15:0"
Columns
=
"8"
TimeFormat
=
"h:mm:tt"
></
TimeView
>
</
telerik:RadDateTimePicker
>
</
td
>
<
td
><
asp:TextBox
ID
=
"txtArriveFlight"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("sd2Flight")%>' Width="38"/></
td
>
</
tr
>
</
table
>
</
td
>
</
tr
><
tr
>
<
td
><
b
>Return: </
td
>
<
td
>
<
table
border
=
"0"
cellpadding
=
"2"
cellspacing
=
"0"
>
<
tr
>
<
td
></
td
>
<
td
style
=
"text-align: center;"
><
b
>Airport</
b
></
td
>
<
td
><
b
>Date/Time</
b
></
td
>
<
td
style
=
"text-align: center;"
><
b
>Flight #</
b
></
td
>
</
tr
><
tr
>
<
td
><
b
>Depart:</
b
></
td
>
<
td
><
asp:TextBox
ID
=
"txtDepartAirport2"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("edAirport")%>' Width="35"/></
td
>
<
td
>
<
telerik:RadDateTimePicker
runat
=
"server"
ID
=
"rdtpStartDate2"
DbSelectedDate='<%# Bind("EndDate") %>' Width="165">
<
TimeView
runat
=
"server"
Interval
=
"0:15:0"
Columns
=
"8"
TimeFormat
=
"h:mm:tt"
></
TimeView
>
</
telerik:RadDateTimePicker
>
</
td
>
<
td
><
asp:TextBox
ID
=
"txtDepartFlight2"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("edFlight")%>' Width="38"/></
td
>
</
tr
><
tr
>
<
td
><
b
>Arrive:</
b
></
td
>
<
td
><
asp:TextBox
ID
=
"txtArriveAirport2"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("ed2Airport")%>' Width="35"/></
td
>
<
td
>
<
telerik:RadDateTimePicker
runat
=
"server"
ID
=
"rdtpsd2StartDate2"
DbSelectedDate='<%# Bind("ed2EndDate") %>' Width="165">
<
TimeView
runat
=
"server"
Interval
=
"0:15:0"
Columns
=
"8"
TimeFormat
=
"h:mm:tt"
></
TimeView
>
</
telerik:RadDateTimePicker
>
</
td
>
<
td
><
asp:TextBox
ID
=
"txtArriveFlight2"
runat
=
"server"
SkinID
=
"TextBox"
Text='<%#Bind("ed2Flight")%>' Width="38"/></
td
>
</
tr
>
</
table
>
</
td
>
</
tr
><
tr
>
<
td
style
=
"vertical-align: top;"
><
b
>Special Notes: </
td
>
<
td
><
asp:TextBox
ID
=
"txtSpecialNotes"
runat
=
"server"
Rows
=
"4"
SkinID
=
"MultiLine"
Text='<%#Bind("SpecialNotes")%>' Width="300" TextMode="MultiLine"/></
td
>
</
tr
>
</
table
>
<
asp:Button
ID
=
"btnUpdate"
runat
=
"server"
CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'
Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'/>
<
asp:Button
ID
=
"btnCancel"
runat
=
"server"
CausesValidation
=
"False"
CommandName
=
"Cancel"
Text
=
"Cancel"
/>
</
FormTemplate
>
</
EditFormSettings
>
<
NoRecordsTemplate
>Please enter flight information here.</
NoRecordsTemplate
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
></
HeaderContextMenu
>
</
telerik:RadGrid
>
<
asp:SqlDataSource
ID
=
"sdsFlightInformation"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:ShowManagerConnectionString %>"
DeleteCommand="UPDATE TravelInfo SET [Active] = @Active WHERE ([TravelInfoID] = @TravelInfoID)"
InsertCommand="INSERT INTO TravelInfo(ShowID, ATSStaffID, ProviderTypeID, ProviderName, Confirmation, sdAirport, StartDate, sdFlight, sd2Airport, sd2StartDate, sd2Flight, edAirport, EndDate, edFlight, ed2Airport, ed2EndDate, ed2Flight, SpecialNotes, AddedBy) VALUES (@ShowID, @ATSStaffID, @ProviderTypeID, @ProviderName, @Confirmation, @sdAirport, @StartDate, @sdFlight, @sd2Airport, @sd2StartDate, @sd2Flight, @edAirport, @EndDate, @edFlight, @ed2Airport, @ed2EndDate, @ed2Flight, @SpecialNotes, @AddedBy)"
SelectCommand="SELECT uvwTravelInformation.TravelInfoID, uvwTravelInformation.DisplayName, uvwTravelInformation.ProviderName, uvwTravelInformation.Confirmation, uvwTravelInformation.ATSStaffID, TravelInfo.sdAirport, TravelInfo.StartDate, TravelInfo.sdFlight, TravelInfo.sd2Airport, TravelInfo.sd2StartDate, TravelInfo.sd2Flight, TravelInfo.edAirport, TravelInfo.EndDate, TravelInfo.edFlight, TravelInfo.ed2Airport, TravelInfo.ed2EndDate, TravelInfo.ed2Flight, TravelInfo.SpecialNotes FROM uvwTravelInformation LEFT OUTER JOIN TravelInfo ON uvwTravelInformation.TravelInfoID = TravelInfo.TravelInfoID WHERE (uvwTravelInformation.ShowID = @ShowID) AND (uvwTravelInformation.ProviderTypeID = 13) ORDER BY uvwTravelInformation.DisplayName"
UpdateCommand="UPDATE TravelInfo SET ProviderName = @ProviderName, Confirmation = @Confirmation, sdAirport = @sdAirport, StartDate = @StartDate, sdFlight = @sdFlight, sd2Airport = @sd2Airport, sd2StartDate = @sd2StartDate, sd2Flight = @sd2Flight, edAirport = @edAirport, EndDate = @EndDate, edFlight = @edFlight, ed2Airport = @ed2Airport, ed2EndDate = @ed2EndDate, ed2Flight = @ed2Flight, SpecialNotes = @SpecialNotes WHERE (TravelInfoID = @TravelInfoID)">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"Active"
DefaultValue
=
"0"
/>
<
asp:Parameter
Name
=
"TravelInfoID"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:QueryStringParameter
Name
=
"ShowID"
QueryStringField
=
"sid"
Type
=
"Int64"
/>
<
asp:Parameter
Name
=
"ATSStaffID"
/>
<
asp:Parameter
Name
=
"ProviderTypeID"
DefaultValue
=
"13"
/>
<
asp:Parameter
Name
=
"ProviderName"
/>
<
asp:Parameter
Name
=
"Confirmation"
/>
<
asp:Parameter
Name
=
"sdAirport"
/>
<
asp:Parameter
Name
=
"StartDate"
/>
<
asp:Parameter
Name
=
"sdFlight"
/>
<
asp:Parameter
Name
=
"sd2Airport"
/>
<
asp:Parameter
Name
=
"sd2StartDate"
/>
<
asp:Parameter
Name
=
"sd2Flight"
/>
<
asp:Parameter
Name
=
"edAirport"
/>
<
asp:Parameter
Name
=
"EndDate"
/>
<
asp:Parameter
Name
=
"edFlight"
/>
<
asp:Parameter
Name
=
"ed2Airport"
/>
<
asp:Parameter
Name
=
"ed2EndDate"
/>
<
asp:Parameter
Name
=
"ed2Flight"
/>
<
asp:Parameter
Name
=
"SpecialNotes"
/>
<
asp:SessionParameter
Name
=
"AddedBy"
SessionField
=
"ATSStaffID"
/>
</
InsertParameters
>
<
SelectParameters
>
<
asp:QueryStringParameter
Name
=
"ShowID"
QueryStringField
=
"sid"
Type
=
"Int64"
/>
</
SelectParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"ProviderName"
/>
<
asp:Parameter
Name
=
"Confirmation"
/>
<
asp:Parameter
Name
=
"sdAirport"
/>
<
asp:Parameter
Name
=
"StartDate"
/>
<
asp:Parameter
Name
=
"sdFlight"
/>
<
asp:Parameter
Name
=
"sd2Airport"
/>
<
asp:Parameter
Name
=
"sd2StartDate"
/>
<
asp:Parameter
Name
=
"sd2Flight"
/>
<
asp:Parameter
Name
=
"edAirport"
/>
<
asp:Parameter
Name
=
"EndDate"
/>
<
asp:Parameter
Name
=
"edFlight"
/>
<
asp:Parameter
Name
=
"ed2Airport"
/>
<
asp:Parameter
Name
=
"ed2EndDate"
/>
<
asp:Parameter
Name
=
"ed2Flight"
/>
<
asp:Parameter
Name
=
"SpecialNotes"
/>
<
asp:Parameter
Name
=
"TravelInfoID"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
0
Hello Michael,
In order to implement the desired functionality, I recommend that you set default values in the edit form when the grid is in insert mode. This can be done with the following code:
You can access the selected items and their values through the SelectedItems property of the RadGrid.
I hope this helps.
Best wishes,
Mira
the Telerik team
In order to implement the desired functionality, I recommend that you set default values in the edit form when the grid is in insert mode. This can be done with the following code:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
{
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
TextBox txt1 = (TextBox)insertItem.FindControl(
"txtProviderName"
);
txt1.Text =
"default text"
;
// fill TextBox with some default data
//you can use the same logic for the other controls as well
}
}
I hope this helps.
Best wishes,
Mira
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.