我在每个地方都用谷歌搜索过,但没有明确的答案,我正在尝试使用以下代码使用详细视图更新记录:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" DataKeyNames="Rec_ID" DataSourceID="ContactsMasterDS"
ForeColor="Black" GridLines="None" PageSize="3">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Full_Name" HeaderText="Full_Name" SortExpression="Full_Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="AgeGroup" HeaderText="AgeGroup" SortExpression="AgeGroup" />
<asp:BoundField DataField="Nationality" HeaderText="Nationality" SortExpression="Nationality" />
<asp:BoundField DataField="Occupation" HeaderText="Occupation" SortExpression="Occupation" />
<asp:BoundField DataField="Resident" HeaderText="Resident" SortExpression="Resident" />
</Columns>
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
<asp:SqlDataSource ID="ContactsMasterDS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="Select * from Contacts"></asp:SqlDataSource>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="Rec_ID" DataSourceID="ContactsDetailsDS" Height="50px"
Width="545px" onitemupdated="DetailsView1_ItemUpdated">
<Fields>
<asp:BoundField DataField="Rec_ID" HeaderText="Rec_ID" ReadOnly="True" SortExpression="Rec_ID" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="AgeGroup" HeaderText="AgeGroup" SortExpression="AgeGroup" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Full_Name" HeaderText="Full_Name" SortExpression="Full_Name" />
<asp:BoundField DataField="DOB" HeaderText="DOB" SortExpression="DOB" />
<asp:BoundField DataField="Phone_No" HeaderText="Phone_No" SortExpression="Phone_No" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Nationality" HeaderText="Nationality" SortExpression="Nationality" />
<asp:BoundField DataField="Account_No" HeaderText="Account_No" SortExpression="Account_No" />
<asp:BoundField DataField="Occupation" HeaderText="Occupation" SortExpression="Occupation" />
<asp:BoundField DataField="Resident" HeaderText="Resident" SortExpression="Resident" />
<asp:BoundField DataField="Room_No" HeaderText="Room_No" SortExpression="Room_No" />
<asp:BoundField DataField="Last_Branch" HeaderText="Last_Branch" SortExpression="Last_Branch" />
<asp:BoundField DataField="Last_Date" HeaderText="Last_Date" SortExpression="Last_Date" />
<asp:BoundField DataField="Last_Time" HeaderText="Last_Time" SortExpression="Last_Time" />
<asp:CheckBoxField DataField="isComplete" HeaderText="isComplete" SortExpression="isComplete" />
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="ContactsDetailsDS" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="Select * from Contacts where [Rec_ID] = @Rec_ID"
UpdateCommand="Update Contacts Set Room_No=@Room_No Where Rec_ID=@Rec_ID" >
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Rec_ID" PropertyName="SelectedValue" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Room_No" Type="String" />
<asp:Parameter Name="Rec_ID" Type="String" DefaultValue="0" />
</UpdateParameters>
</asp:SqlDataSource>
当我将 where 子句更改为“Where Rec_ID = 2”时,它可以工作,但是当使用参数时,它不会进行所需的更新,请提供任何帮助