2011-10-04 88 views

回答

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> 

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

只需在您不希望人们编辑的列上设置ReadOnly选项为true即可。在编辑模式下,用户可以编辑没有这个设置或者ReadOnly设置为false的列。

+0

你可以举例 –

+1

增加一个例子 – Kirk

+0

可以请你帮我一下吗? http://stackoverflow.com/questions/7654434/solution-for-selecting-and-editing-data-at-the-same-time –

3

如果你使用一个SqlDataSource,那么你应该确保删除列从更新命令中的SqlDataSource更新如果不是你将有一个问题,当你更新字段