且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Telerik的radgrid控件在编辑模式下设置绑定列到只读

更新时间:2022-10-15 07:38:30

只需将只读属性真正。请参见下面的例子:

 < Telerik的:GridBoundColumn数据字段=日期时间的HeaderText =日期
DataFormatString = {0:MM / DD / YYYY}只读=真>
< / Telerik的:GridBoundColumn>


I have a Telerik RadGrid that has three bound columns and one button column. I would like to let the user edit the values in only one of the bound columns. The user can add a new record so i can't set the two bound column to read only. Is there anyway i can do this in the ASPX or do i have to do it in the code behind? I have some code that is working but it is not the best.

Here's my code:

Case "Edit"
    Dim aoeAnswerCode As GridBoundColumn = CType(e.Item.OwnerTableView.GetColumn("aoeAnswerCode"), GridBoundColumn)
    aoeAnswerCode.ReadOnly = True

Case "Update", "PerformInsert"
    For Each column As GridColumn In e.Item.OwnerTableView.RenderColumns
        If TypeOf column Is IGridEditableColumn Or column.UniqueName = "aoeAnswerCode" Then

Simply set the ReadOnly property to true. See the example below:

<telerik:GridBoundColumn DataField="Datetime" HeaderText="Date" 
 DataFormatString="{0:MM/dd/yyyy}" ReadOnly="True">  
</telerik:GridBoundColumn>