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

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

问题描述

我有一个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!

这是可能的吗?

推荐答案

只读=真属性在所有你不想编辑。

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

看看<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.readonly.aspx\">http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.readonly.aspx

从该网页一个简单的例子

A quick example from that page

<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>

在这种情况下的客户ID 公司名称是只读的,不能改变。 地址 城市邮政code 可以编辑。

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

只需设置只读选项设置为true的列,你不希望人们编辑。没有这一套或已经只读设置为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天全站免登陆