Telerik RadGrid 在编辑模式下将 BoundColumn 设置为 ReadOnly

发布于 2024-12-25 09:27:12 字数 582 浏览 1 评论 0原文

我有一个 Telerik RadGrid,它具有三个绑定列和一个按钮列。我想让用户仅编辑绑定列之一中的值。用户可以添加新记录,因此我无法将两个绑定列设置为只读。无论如何,我可以在 ASPX 中执行此操作还是必须在后面的代码中执行此操作?我有一些代码可以工作,但它不是最好的。

这是我的代码:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

澉约 2025-01-01 09:27:12

只需将 ReadOnly 属性设置为 true 即可。请参阅下面的示例:

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

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>
白芷 2025-01-01 09:27:12

.aspx 页面代码

 <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>

aspx.cs 页面代码

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode && e.Item is GridEditableItem)
    {
        if (e.Item.ItemIndex == -1)
        {
            // insert
            GridEditableItem item = e.Item as GridEditableItem;

        }
        else
        {
            // edit
            GridEditableItem item = e.Item as GridEditableItem;
            (item["ID"].Controls[0] as TextBox).ReadOnly = true;
        }

    }
}

.aspx page code

 <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>

aspx.cs page code

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode && e.Item is GridEditableItem)
    {
        if (e.Item.ItemIndex == -1)
        {
            // insert
            GridEditableItem item = e.Item as GridEditableItem;

        }
        else
        {
            // edit
            GridEditableItem item = e.Item as GridEditableItem;
            (item["ID"].Controls[0] as TextBox).ReadOnly = true;
        }

    }
}
你不是我要的菜∠ 2025-01-01 09:27:12
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode && e.Item is GridEditFormItem)
    {
            // edit
            GridEditFormItem item = e.Item as GridEditFormItem;
            (item["column"].Controls[0] as TextBox).Enabled = false;
    }
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode && e.Item is GridEditFormItem)
    {
            // edit
            GridEditFormItem item = e.Item as GridEditFormItem;
            (item["column"].Controls[0] as TextBox).Enabled = false;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文