Telerik RadGrid - 如何在插入时设置默认数据? [英] Telerik RadGrid - How do I set default data on insert?

查看:44
本文介绍了Telerik RadGrid - 如何在插入时设置默认数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I click on the add record button I want one of my columns to have a default value in it. How do I do this in the code behind? It is a dynamic date and can change all the time?

推荐答案

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

If the column is not a GridTemplateColumn, you can specify a default value using the column's DefaultInsertValue property, like this:

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

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

Otherwise, if it is a GridTemplateColumn, take a look at the following Telerik article :

使用 InPlace 和 EditForms 插入值模式

更新:

您还可以在代码隐藏中使用 ItemCommand 方法指定默认列值:

You can also specify the default column values using the ItemCommand method in your code-behind:

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 - 如何在插入时设置默认数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆