1. Can add multiple records at a time. If so how? What I envision, is the the grid loads, you click add new record, fill out the in-line form, click Add New record, and a new row is appended in edit mode still, tehn at teh end a sdingle postback sends all rows to the database.
2. How can I set a GridDateTimeColumn editor to "Today's Date"
3. How can I set a GridDropDownColumn editor to not wrap the options in the drop down list
4.How can I "pre-populate" a field with the current UserID when the grid is set in "edit" or "Add new record" mode. I envision something like this:
Dim UserID As String |
If RadGrid1.CurrentMode = RadGridMode.Insert Then |
UserID = Membership.GetUser.UserName.ToString() |
CType(Me.RadGrid1.FindControl("UserIDTextbox"), Text).Text = UserID |
End If |
5. How do I make the value of a field be the default for subsequent added records. For example, one column contains population. So after the first row as been added I would like the column to default to the initial value entered in the population field during the same session.
Any help would be great thanks,
Brett
5 Answers, 1 is accepted
1. You can find attached a sample project demonstrating the functionality you requested. InsertCommand places the inserted data into a hashtable and stores in the Session, whereas we have a UpdateAll button in the command item which retrieves the hashtables from the session and you can manually insert them in the data source.
2. For getting the current date in the DateTime editor, you can do the following:
void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) |
{ |
GridEditableItem item = (GridEditableItem)e.Item; |
(item.EditManager.GetColumnEditor("ColumnUniqueName") as GridDateTimeColumnEditor).Text = System.DateTime.Today.ToString(); |
} |
3. To force a GridDropDownListColumnEditor not to wrap, you can set its DropDownStyle.Width to a custom unit in the ItemDataBound event handler:
(item.EditManager.GetColumnEditor("Category") as GridDropDownListColumnEditor).DropDownStyle.Width = Unit.Pixel(80); |
4. To set an initial value to a field in insert mode, you can do the following:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridEditFormInsertItem) |
{ |
GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item; |
(item.EditManager.GetColumnEditor("ProductID") as GridTextBoxColumnEditor).Text = "102"; |
} |
} |
In the ItemDataBound the EditFormInsertItem is referenced and its respective column editor is set. This is also demonstrated in the attached sample project.
5. This question is closely related to the previous one. Again in the ItemDataBound event you can set values for any of the column editors you have in your grid. You can also store values in the session and place them in the editors.
Greetings,
Veli
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

I have been trying to get some of the code to work but without much luck. Ihave been using code converter to move it over to VB, but am getting some syntax errors.
Current DateTime: Syntax Error - Line 3
Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) | |
Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) | |
(TryCast(item.EditManager.GetColumnEditor("ColumnUniqueName"), GridDateTimeColumnEditor)).Text = System.DateTime.Today.ToString() | |
End Sub |
NoWrap Drop Down Values: Syntax Error - Line 2
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound | |
(TryCast(item.EditManager.GetColumnEditor("CauseID"), GridDropDownListColumnEditor)).DropDownStyle.Width = Unit.Pixel(80) | |
End Sub |
Seting Default Values: Syntax Error - Line 4
Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) | |
If TypeOf e.Item Is GridEditFormInsertItem Then | |
Dim item As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem) | |
(TryCast(item.EditManager.GetColumnEditor("ProductID"), GridTextBoxColumnEditor)).Text = "102" | |
End If | |
End Sub |
What is teh proper VB method of achiving these tasks?
Thanks again,
Brett
Try the following:
Private Sub RadGrid1_InsertCommand(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand |
Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) |
Dim Editor = CType(item.EditManager.GetColumnEditor("ColumnUniqueName"), GridDateTimeColumnEditor) |
Editor.Text = System.DateTime.Today.ToString() |
End Sub |
And also:
Protected Sub RadGrid1_ItemDataBound(ByVal source As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound |
If TypeOf e.Item Is GridEditFormInsertItem Then |
Dim item = CType(e.Item, GridEditFormInsertItem) |
Dim editor = CType(item.EditManager.GetColumnEditor("ProductID"), GridTextBoxColumnEditor) |
editor.Text = "102" |
End If |
End Sub |
Kind regards,
Veli
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

I am sorry to say I am still not havng much luck with examples you have given. I think I am going to forget about the multiple new records for now and just try and get the features workng.
I have posted my code for vb and aspx, please review and let me know where I have gone wrong.
None of the pre-populated fields are working (UserID/ReportDate) and my dropdown column still is wrapping the text.
Thanks for any insight you can provide.
VB.net
Protected Sub RadGrid1_InsertCommand(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand | |
Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) | |
Dim Editor = CType(item.EditManager.GetColumnEditor("ReportDate"), GridDateTimeColumnEditor) | |
Editor.Text = System.DateTime.Today.ToString() | |
End Sub | |
Protected Sub RadGrid1_ItemDataBound(ByVal source As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound | |
If TypeOf e.Item Is GridEditFormInsertItem Then | |
Dim item = CType(e.Item, GridEditFormInsertItem) | |
Dim editor = CType(item.EditManager.GetColumnEditor("UserID"), GridTextBoxColumnEditor) | |
'editor.Text = Membership.GetUser.UserName.ToString() | |
editor.Text = "102" | |
CType(item.EditManager.GetColumnEditor("CauseID"), GridDropDownListColumnEditor).DropDownStyle.Width = Unit.Pixel(80) | |
End If | |
End Sub |
aspx
<
telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="dsSchoolReports"
Skin="WebBlue" GridLines="None" Width="95%" AutoGenerateDeleteColumn="True"
AutoGenerateEditColumn="True" OnItemDataBound="RadGrid1_ItemDataBound" OnInsertCommand="RadGrid1_InsertCommand">
<
MasterTableView autogeneratecolumns="False" datakeynames="id"
datasourceid="dsSchoolReports" AllowAutomaticDeletes="True"
AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
CommandItemDisplay="Bottom" EditMode="InPlace">
<
RowIndicatorColumn Visible="False">
<
HeaderStyle Width="20px"></HeaderStyle>
</
RowIndicatorColumn>
<
ExpandCollapseColumn Visible="False" Resizable="False">
<
HeaderStyle Width="20px"></HeaderStyle>
</
ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="id" DataType="System.Int32" HeaderText="id"
ReadOnly="True" SortExpression="id" UniqueName="id" Visible="False">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SchoolID" DataType="System.Int32"
HeaderText="SchoolID" SortExpression="SchoolID" UniqueName="SchoolID">
</telerik:GridBoundColumn>
<telerik:GridDateTimeColumn DataField="ReportDate" DataType="System.DateTime"
HeaderText="ReportDate" SortExpression="ReportDate"
UniqueName="ReportDate"
PickerType="DatePicker"
ColumnEditorID="ReportDate">
</telerik:GridDateTimeColumn>
<telerik:GridBoundColumn DataField="UserID" DataType="System.Int32"
HeaderText="UserID" SortExpression="UserID" UniqueName="UserID"
ColumnEditorID="UserID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="StudentsAbsent" DataType="System.Int32"
HeaderText="# Absent" SortExpression="StudentsAbsent"
UniqueName="StudentsAbsent" MaxLength="4">
<HeaderStyle Width="100px" />
<ItemStyle Width="50px" />
</telerik:GridBoundColumn>
<%
-- <telerik:GridBoundColumn DataField="CauseID" DataType="System.Int32"
HeaderText="Cause of Absence" SortExpression="CauseID"
UniqueName="CauseID">
</telerik:GridBoundColumn>
<telerik:GridDropDownColumn DataField="CauseID" DataType="System.Int32"
HeaderText="Cause of Absence" SortExpression="CauseID"
UniqueName="CauseID">
</telerik:GridDropDownColumn>--
%>
<telerik:GridDropDownColumn
UniqueName="CauseID"
ListTextField="CauseName"
ListValueField="id"
DataSourceID="dsCauses"
HeaderText="Cause of Absence"
DataField="CauseID"
DropDownControlType="RadComboBox"
AllowSorting="true"
ColumnEditorID="CauseID">
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" Wrap="False" />
</
telerik:GridDropDownColumn>
<telerik:GridBoundColumn DataField="SchoolPopulation" DataType="System.Int32"
HeaderText="School Population" SortExpression="SchoolPopulation"
UniqueName="SchoolPopulation">
</telerik:GridBoundColumn>
</Columns>
<
EditFormSettings>
<
PopUpSettings ScrollBars="None"></PopUpSettings>
</
EditFormSettings>
</
MasterTableView>
</telerik:RadGrid>
Brett
The sample code you provided seems fine. I wonder why it does not work at your site. If the problem persists, please consider opening a regular support ticket where you can provide us a sample runnable project, so that we can look into the matter and advise you further.
Regards,
Veli
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center