我有這個GridView
在我的網站:的GridView與SqlDataSource的更新將無法正常工作
<asp:GridView ID="ClientGridView" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" DataKeyNames="id,email,first,last">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
onclientclick="javascript:return confirm('are you sure you want to delete.');" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id"/>
<asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
<asp:BoundField DataField="first" HeaderText="first" SortExpression="first"/>
<asp:BoundField DataField="last" HeaderText="last" SortExpression="last" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
這是SqlDataSource
:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:clientConnectionString %>"
ProviderName="<%$ ConnectionStrings:clientConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM Client;"
DeleteCommand="DELETE FROM Client WHERE id = @id AND email = @email;"
UpdateCommand="UPDATE Client SET first = @first WHERE id = @id;">
<DeleteParameters>
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="email" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="first" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
,當我嘗試到EXCUTE在一排更新它保持相同的值,不會更新,任何想法如何解決它?
我的猜測,沒有編譯器手頭,是將DataKeyNames更改爲「id」而不是複合,逗號分隔列表你現在有。 – 2013-03-04 18:35:33
你的更新語句只需要兩個參數,你傳遞4? – 2013-03-04 18:35:37
這只是爲了我的測試...它仍然不會工作.... – MTA 2013-03-04 18:37:49