我用Google搜索每一個地方,但沒有一個明確的答案 我嘗試使用下面的代碼使用詳細信息視圖更新記錄:的DetailView更新不工作
<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 [email protected]_No Where [email protected]_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子句是「凡·REC_ID = 2" 它的工作原理,但使用參數時它不這樣做所需的更新 任何幫助,請
嘗試改變這一點:
briskovich
沒有它沒有工作 –
嘗試這個。使您的Rec_Id成爲標籤而不是文本框。幾周前我遇到了這個問題,而且工作。和 convert(varchar,rec_id)LIKE @rec_id。 – briskovich