允许编辑一列但不允许编辑另一列 [英] Allowing one column to be edited but not another

查看:26
本文介绍了允许编辑一列但不允许编辑另一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 asp.net c# 应用程序.

i have an asp.net c# application.

我的 gridview 有一个包含 2 个字段的数据源.

my gridview has a datasource that has 2 fields.

用户无法编辑 1 个字段,但我需要另一个字段可编辑!

1 field cannot be edited by the user, but i need the other one to be editable!

这可以吗?

推荐答案

在所有不想编辑的地方设置 ReadOnly="true" 属性.

Set the ReadOnly="true" property on all that you don't want editable.

看看 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.readonly.aspx

该页面的一个简单示例

<asp:gridview id="CustomersGridView" 
    datasourceid="CustomersSqlDataSource" 
    autogeneratecolumns="false"
    autogenerateeditbutton="true"
    allowpaging="true" 
    datakeynames="CustomerID"  
    runat="server">

    <columns>
      <asp:boundfield datafield="CustomerID" readonly="true" headertext="Customer ID"/>
      <asp:boundfield datafield="CompanyName" readonly="true" headertext="Customer Name"/>
      <asp:boundfield datafield="Address" headertext="Address"/>
      <asp:boundfield datafield="City" headertext="City"/>
      <asp:boundfield datafield="PostalCode" headertext="ZIP Code"/>
    </columns>
</asp:gridview>

在这种情况下,CustomerID公司 名称是只读的,不能更改.地址城市邮政编码可以编辑.

In this case CustomerID and Company name are read only and can't change. Address, City and PostalCode can be edited.

只需在您不希望人们编辑的列上将 ReadOnly 选项设置为 true.在编辑模式下,用户可以编辑未设置此设置或将 ReadOnly 设置为 false 的列.

Just set the ReadOnly option to true on the columns you DON'T want people to edit. The columns that don't have this set or have ReadOnly set to false are editable by the user when in edit mode.

这篇关于允许编辑一列但不允许编辑另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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