DataList删除操作

<asp:DataList ID="fileList" runat="server" RepeatColumns="1" RepeatDirection="Horizontal"
CssClass="body" DataKeyField="ContentID" OnItemCommand="fileList_ItemCommand">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="width: 760px">
  <tr>
    <td style="width: 760px; text-align: center">
      <a href='<%# SetFileUrl(DataBinder.Eval(Container.DataItem, "ContentName"))%>'>
        <%# SetFileName(DataBinder.Eval(Container.DataItem, "ContentName"))%></a>
    </td>
  </tr>
  <tr>
    <td style="width: 760px; text-align: center">
      <iframe id="fileview" name="fileview" width="760px" height="600px" src='<%# GetFilePath(DataBinder.Eval(Container.DataItem,                       "ContentName"),DataBinder.Eval(Container.DataItem, "FileType"))%>'>
      </iframe>
    </td>
  </tr>
  <tr>
    <td style="width: 760px; text-align: center; height: 18px;">
      <asp:ImageButton ID="imgBtnDelete" runat="server" CommandName="del" ImageUrl="~/images/btn_delete.png"
         OnClientClick="return ConfirmDelete()" />
    </td>
  </tr>
</table>
</ItemTemplate>
</asp:DataList>

 

protected void fileList_ItemCommand(object source, DataListCommandEventArgs e)
{
  int menuId;
  string contentName = string.Empty;
  bool result = true;
  if (e.CommandName == "del")
  {
    int id = Int32.Parse(fileList.DataKeys[e.Item.ItemIndex].ToString());
    result = bllConent.DeleteItem(id, out menuId, out contentName);

    if (result)
    {
      result = AndroidKit.Common.ComHelper.DeleteFile(contentName);
      BindData(menuId);
      Response.Write("<script>alert(\"删除成功\")</script>");
    }
  }
}

posted @ 2013-06-17 01:32  Vihone  阅读(339)  评论(0编辑  收藏  举报