gpt4 book ai didi

Telerik RadGrid - 如何在插入时设置默认数据?

转载 作者:行者123 更新时间:2023-12-04 05:14:56 24 4
gpt4 key购买 nike

当我单击添加记录按钮时,我希望其中一列具有默认值。我如何在后面的代码中做到这一点?它是一个动态日期并且可以一直更改?

最佳答案

如果该列不是 GridTemplateColumn ,您可以使用列的 DefaultInsertValue 指定默认值属性,像这样:

<telerik:GridBoundColumn DefaultInsertValue="12/21/2012" DataType="System.DateTime" DataField="Column1" UniqueName="Column1"></telerik:GridBoundColumn>

否则,如果是 GridTemplateColumn ,看看下面的 Telerik 文章:

Inserting Values Using InPlace and EditForms Modes

更新 :

您还可以使用 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

关于Telerik RadGrid - 如何在插入时设置默认数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14406276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com