怎么在DataList实现删除单条记录?
前台:在 DataList 里面用一个button 按钮,实现删除该条里面的数据
<asp:DataList ID="dlRevertCard" runat="server" Width="478px" Height="1px">
<ItemTemplate>
<table style="width: 478px" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 478px; background-image: url(../../Image/标头.jpg); text-indent: 2pt; height: 22px;" align="left">
<asp:Label ID="Label6" runat="server" Font-Size="9pt" Text="回帖内容"></asp:Label></td>
</tr>
<tr>
<td style="width: 478px; background-image: url(../../Image/文本.jpg); vertical-align: top; text-indent: 8pt; height: 54px;" align="left">
<asp:Label ID="Label7" runat="server" Enabled="True" Font-Size="9pt" Width="387px" Text='<%# DataBinder.Eval(Container.DataItem,"RevertCardContent") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 478px; background-image: url(../../Image/时间.jpg); height: 22px;" align="right">
<asp:Label ID="Label8" runat="server" Font-Size="9pt" Text="回帖日期:"></asp:Label>
<asp:Label ID="labRevertCardDate" runat="server" Font-Size="9pt" Text='<%# DataBinder.Eval(Container.DataItem,"RevertCardDate") %>'></asp:Label>
<asp:button ID="sc" runat="server" Font-Size="9pt" CommandName="command" CommandArgument="commandargument" CausesValidation="true" OnClick="sc_Click" Text="删除" /> </td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
后台代码:
protected void sc_Click(object sender, EventArgs e)
{
string userID = e.CommandArgument.ToString();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = db.createCon();
cmd.CommandText = "delete from tb_RevertCard where RevertCardID='" + userID + "'";
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("<script>alert('删除成功!');window.location=window.location;</script>");
}
else
{
Response.Write("<script>alert('删除失败!');window.location=window.location;</script>");
}
}
实现不了?那里有问题啊?