<asp:SqlDataSource ID="HopefulDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand= "SELECT id, regGroupID, amountReceived, other FROM table"
UpdateCommand="UPDATE table
SET [amountReceived] = @amountReceived
WHERE [regGroupID] = @regGroupID">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCourses" Name="ddlSelectedCourse" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="regGroupID" Type="Int32" />
<asp:Parameter Name="amountReceived" Type="Decimal" />
other parameters
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
当我将“WHERE [regGroupID] = @regGroupID”更改为任一时,上述内容有效
哪里 [id] = @id
or
其中 [regGroupID] = 2
您需要将“regGroupID”添加到DataKeyNames
收藏在你的GridView
宣言。像这样的事情:
<asp:GridView ID="yourGridViewId" DataKeyNames="regGroupID" ... >
...
</asp:GridView>
See the DataKeyNames文档 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames.aspx:
您必须设置 DataKeyNames 属性才能自动
GridView 控件的更新和删除功能才能正常工作。价值
这些关键字段的一部分被传递到数据源控件,以便
指定要更新或删除的行。
注意:我已经有一段时间没有使用它了,所以您可能需要同时包含主键和其他键字段。像这样:
DataKeyNames="id,regGroupID"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)