1
我有2個表格MachineGroups和Machines。 MachineGroups有列:從gridview刪除行
MachinegroupID
MachineGroupName
MachineGroupDesc
和機器中的列:
MachineGroupID (FK)
MachineID
MachineName
Machinedesc
現在我想刪除machinegroup,但不是必須的機器在裏面的人。
DELETE FROM MachineGroups
WHERE MachineGroupID NOT IN (SELECT DISTINCT MachineGroupID FROM Machines)
這將刪除gridview中沒有的所有行。機器= 0 我要的是隻刪除其刪除鏈接被點擊的行...
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="1" CellSpacing="2"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"
Width="100%" ondatabound="GridView1_DataBound1"
onrowdatabound="GridView1_RowDataBound1">
<RowStyle BackColor="#D0D8E8" ForeColor="#333333" Height="35px" />
<Columns>
<asp:BoundField DataField="MachineGroupID" HeaderText="MachineGroupID"
InsertVisible="False" ReadOnly="True" SortExpression="MachineGroupID"
Visible="False" />
<asp:BoundField DataField="MachineGroupName" HeaderText="MachineGroupName"
SortExpression="MachineGroupName" />
<asp:BoundField DataField="MachineGroupDesc" HeaderText="MachineGroupDesc"
SortExpression="MachineGroupDesc" />
<asp:BoundField DataField="TimeAdded" HeaderText="TimeAdded"
SortExpression="TimeAdded" />
<asp:TemplateField HeaderText="CanBeDeleted" SortExpression="CanBeDeleted"
Visible="False">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# Bind("CanBeDeleted") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# Bind("CanBeDeleted") %>' Enabled="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="No. of PCs" HeaderText="No. of PCs" ReadOnly="True"
SortExpression="No. of PCs" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SumooHAgentDBConnectionString %>"
SelectCommand="SELECT MachineGroups.MachineGroupID, MachineGroups.MachineGroupName, MachineGroups.MachineGroupDesc, MachineGroups.TimeAdded, MachineGroups.CanBeDeleted, COUNT(Machines.MachineName) AS 'No. of PCs' FROM MachineGroups FULL OUTER JOIN Machines ON Machines.MachineGroupID = MachineGroups.MachineGroupID GROUP BY MachineGroups.MachineGroupID, MachineGroups.MachineGroupName, MachineGroups.MachineGroupDesc, MachineGroups.TimeAdded, MachineGroups.CanBeDeleted"
DeleteCommand="DELETE FROM MachineGroups
WHERE MachineGroupID NOT IN (SELECT DISTINCT MachineGroupID FROM Machines)">
<DeleteParameters>
<asp:Parameter Name="original_MachineGroupID" />
<asp:Parameter Name="original_MachineGroupName" />
<asp:Parameter Name="original_MachineGroupDesc" />
<asp:Parameter Name="original_CanBeDeleted" />
<asp:Parameter Name="original_TimeAdded" />
</DeleteParameters>
</asp:SqlDataSource>
@unknown:你需要了解如何正確格式化XML和代碼片段!突出顯示有問題的行,然後單擊編輯工具欄上的「代碼」按鈕(010 101),或者在鍵盤上按下Ctrl-K - 只有代碼正確顯示並且其他人才能看到回答您的問題! – 2009-09-28 05:49:55
謝謝..我記得下次 – user175084 2009-09-28 05:55:00