允许编辑一列但不允许编辑另一列

l--*_*''' 7 c# asp.net gridview

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

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

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

这可能吗?

Kir*_*irk 22

ReadOnly="true"在您不想编辑的所有内容上设置属性.

看看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>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,CustomerID和Company名称是只读的,不能更改.地址,城市和POSTALCODE可以进行编辑.

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