在GridView中编辑两个列,保留其他列'数据完整

时间:2016-03-26 12:38:19

标签: c# sql asp.net gridview datafield

我的asp.net项目中有GrideView,我想只编辑两列, 我使用Read-Only="true"属性,但问题是在编辑了两列后,其他人的数据变空了! 请帮我解决这个问题。

<Columns>
   <asp:HyperLinkField DataNavigateUrlFields="RNum" DataNavigateUrlFormatString="WebForm2.aspx?RNum={0}" DataTextField="RNum" HeaderText="No" />
   <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" ReadOnly="true"/>
   <asp:BoundField DataField="AssignTo" HeaderText="AssignTo" SortExpression="AssignTo" />
   <asp:BoundField DataField="Priority"   HeaderText="Priority" SortExpression="Priority" ReadOnly="true" />
   <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
   <asp:BoundField DataField="UserName"   HeaderText="Requested By" SortExpression="UserName" ReadOnly="true" />
   <asp:BoundField DataField="ddate"  HeaderText="Date" SortExpression="ddate" ReadOnly="true" />
</Columns>

1 个答案:

答案 0 :(得分:0)

您必须修改基础SqlDataSource Update命令属性,如下例所示:

UpdateCommand="Update Employees SET FirstName=@FirstName,LastName=@LastName,Title=@Title WHERE EmployeeID=@EmployeeID"

(re:https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updatecommand(v=vs.110).aspx