DetailsView控件的总结

这个控件是用来显示书的详细信息的。

1.先查询书的所有信息显示出来。

2.添加ItemInserting事件激发时,书的类别和书的出版社的值对象要重新设置,

        ///类别

        Category cate = new Category();
        DropDownList dro = (this.DetailsView1.FindControl("DropDownList1"))as DropDownList;
        cate.Name = dro.SelectedItem.Text;
        cate.Id = Convert.ToInt32(dro.SelectedValue);
        BookManager.Cate = cate;

        ///出版社

        Publisher pub = new Publisher();
        DropDownList dropub = (this.DetailsView1.FindControl("DropDownList2")) as DropDownList;
        pub.Id =Convert.ToInt32(dropub.SelectedItem.Value);
        pub.Name = dropub.SelectedItem.Text;
        BookManager.Pub = pub;

        传递给BLL.BookManager的InsertBooks(Book books)方法。

            /// <summary>
        /// 注意字段和属性都为静态
        /// </summary>
        private static Category cate;

        public static Category Cate
        {
           
            set {  BookManager.cate= value; }
        }
        private static Publisher pub;

        public static Publisher Pub
        {
           
            set { BookManager.pub = value; }
        }

3.更新ItemUpdating事件激发时,书的类别和书的出版社的值对象要重新设置。跟上面方法一样。

4.删除的时候如果涉及到图片,得在ItemDeleting事件中先删除图片

         Image image = (DetailsView1.FindControl("Image1")) as Image;
        File.Delete(image.ImageUrl);

5.插入书的信息以后在来把图片上传到服务器上,在Inserted事件里编写。

          if (e.Exception == null)
        {
            string Isbn = ((DetailsView1.FindControl("txtIsbninsert")) as TextBox).Text;
            string path = Server.MapPath("~/BookCovers/" + Isbn + ".jpg");
            FileUpload fileupload = (DetailsView1.FindControl("FileUpload2")) as FileUpload;
            if (fileupload != null && fileupload.HasFile ==true && fileupload.FileName!=null)
            {
            fileupload.SaveAs(path);
            Response.Write("<script>alert('图片添加成功!')</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('图片添加失败!')</script>");
        }

6.更新书的信息以后在来把服务器上的图片更新掉。在Update事件里编写。与以上一样。

 

谈谈authentication的用法。

在web.config.文件里编写一下。

<!--
            通过 <authentication> 节可以配置 ASP.NET 使用的
            安全身份验证模式,
            以标识传入的用户。
        -->
  <authentication mode="Forms">
   <forms defaultUrl="indexView.aspx" loginUrl="Login.aspx">
   </forms>
  </authentication>

然后用户登录成功后这样设置

 FormsAuthentication.RedirectFromLoginPage(txtName.Text.Trim(),false);

这是使用Forms身份验证cookie的指定路径。可将经过身份验证的用户重定向最初请求的URL或默认的URL.

 

在GridView 里删除的另一种方法。

<asp:TemplateField HeaderText="删除">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" CommandName="del" CommandArgument='<%# Eval("TypeID")%>' ImageUrl="~/images/delete.gif" OnClientClick="return confirm('你是否确定删除');" />
                </ItemTemplate>
            </asp:TemplateField>

然后在删除的事件中编写

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            HotelManager.Model.RoomType type = new HotelManager.Model.RoomType();
            type.TypeID = Convert.ToInt32(e.CommandArgument.ToString());
            RoomTypeBLL roomtypebll = new RoomTypeBLL();
            bool bo = roomtypebll.DeleteRoomType(type);
            if (bo)
            {
                Response.Write("<script>alert('删除成功!')</script>");
                this.DataBind();
            }
            else
            {
                Response.Write("<script>alert('删除失败!')</script>");
            }
        }
    }

这样就可成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值