我的页面上有以下中继器:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"
onitemcommand="Repeater1_ItemCommand">
<ItemTemplate>
<div id="fullcommentheader">
<span class="fullname">
<asp:Literal ID="Literal3" runat="server" Text='<%# Eval("Name") %>'></asp:Literal></span>
<br />
<span class="fullbodytext">
<asp:Button ID="Button2" runat="server" CommandName="Delete" CommandArgument='<%# Eval("Id") %>' Text="Delete" />
<asp:Literal ID="LitBody2" Text='<%# Eval("Message")%>' runat="server"></asp:Literal></span>
<span class="dateTime">
<asp:Literal ID="Literal4" runat="server" Text='<%# Eval("CreateDateTime") %>'></asp:Literal></span>
</div>
<br />
</ItemTemplate>
</asp:Repeater>
我有一个Button2,我想用它来删除转发器条目,我如何查询数据库来实现这一点?我习惯在gridview上默认使用这些命令,所以我不确定如何手动执行此操作。
我的活动:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Delete" && e.CommandArgument.ToString() != "")
{
}
}
这是我的 SqlDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:orangefreshConnectionString1 %>"
DeleteCommand="DELETE FROM [Comment] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [Comment] ([Name], [Email], [Website], [Message], [PostId]) VALUES (@Name, @Email, @Website, @Message, @PostId)"
SelectCommand="SELECT [Name], [Email], [Website], [Message], [PostId], [Id], [CreateDateTime] FROM [Comment] WHERE ([PostId] = @PostId)"
UpdateCommand="UPDATE [Comment] SET [Name] = @Name, [Email] = @Email, [Website] = @Website, [Message] = @Message, [PostId] = @PostId, [CreateDateTime] = @CreateDateTime WHERE [Id] = @Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Website" Type="String" />
<asp:Parameter Name="Message" Type="String" />
<asp:QueryStringParameter Name="PostId" QueryStringField="Id" Type="Int32" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="PostId" QueryStringField="Id" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Website" Type="String" />
<asp:Parameter Name="Message" Type="String" />
<asp:Parameter Name="PostId" Type="Int32" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>