当我单击“添加记录”按钮时,我希望其中一列具有默认值。我如何在后面的代码中做到这一点?这是一个动态日期并且可以随时更改?
如果该列不是GridTemplateColumn
,您可以使用列的指定默认值DefaultInsertValue
属性,像这样:
<telerik:GridBoundColumn DefaultInsertValue="12/21/2012" DataType="System.DateTime" DataField="Column1" UniqueName="Column1"></telerik:GridBoundColumn>
否则,如果它是一个GridTemplateColumn
,请看以下 Telerik 文章:
使用 InPlace 和 EditForms 模式插入值 http://www.telerik.com/help/aspnet-ajax/grid-inserting-values-inplace-and-editforms.html
Update:
您还可以使用以下命令指定默认列值ItemCommand
代码隐藏中的方法:
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
If (e.CommandName = RadGrid.InitInsertCommandName) Then
'cancel the default operation
e.Canceled = True
'Prepare an IDictionary with the predefined values
Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary()
newValues("Column1") = New DateTime(2013, 1, 22)
newValues("Column2") = "hello"
newValues("Column3") = Nothing
'Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues)
End If
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)