public void GV_RowCommand(Object sender, GridViewCommandEventArgs e)
        {
            int index = Convert.ToInt32(e.CommandArgument);
            int topicId = -1;
            switch (e.CommandName)
            {
                case "Update":
                    topicId = Convert.ToInt32(GV.Rows[index].Cells[0].Text);
                    Response.Redirect("TopicUpdate.aspx?topic_id=" + topicId.ToString());
                    break;
                case "Delete":
                    topicId = Convert.ToInt32(GV.Rows[index].Cells[0].Text);
                    Topic topic = new Topic();
                    topic.LoadData(topicId);
                    topic.Delete();
                    break;
                default:
                    break;
            }
            Response.Redirect("TopicList.aspx");
        }
        public void GV_RowDeleting(Object sender, GridViewDeleteEventArgs e)
        {
            string userloginnameofTopic = GV.Rows[e.RowIndex].Cells[1].Text.ToString();
            if (userloginnameofTopic == "guest" || userloginnameofTopic != Session["login_name"].ToString())
            {
                Response.Write("<script Language=javascript>alert('你无权删除!')</script>");
                e.Cancel = true;
            }
        }上面是topiclist.aspx.cs的代码
我想问就是,当我点删除时为什么没有经过权限的验证就直接把主题删除了,还有就是想问。
 public void GV_RowDeleting(Object sender, GridViewDeleteEventArgs e)
这个事件是什么时候触发的??~??

解决方案 »

  1.   

    先看RowDeleting事件触发了吗.
    再看一下if里边的执行了吗.单击某一行的“删除”按钮后,在 GridView 控件删除该行之前,将引发 RowDeleting 事件。这使您可以提供一个这样的事件处理方法,即每次发生此事件时执行一个自定义例程(如取消删除操作)。GridViewDeleteEventArgs 对象将被传递给事件处理方法,以便您可以确定当前行的索引,还可以指示应取消删除操作。若要取消删除操作,请将 GridViewDeleteEventArgs 对象的 Cancel 属性设置为 true。
      

  2.   

    没进事件或条件不成立。
    GridView有一个列是可以编辑删除的,点哪个删除时候触发。
      

  3.   

    可是我点删除时!~~~那就
    public void GV_RowCommand(Object sender, GridViewCommandEventArgs e) 
            { 
                int index = Convert.ToInt32(e.CommandArgument); 
                int topicId = -1; 
                switch (e.CommandName) 
                { 
                    case "Update": 
                        topicId = Convert.ToInt32(GV.Rows[index].Cells[0].Text); 
                        Response.Redirect("TopicUpdate.aspx?topic_id=" + topicId.ToString()); 
                        break; 
                    case "Delete": 
                        topicId = Convert.ToInt32(GV.Rows[index].Cells[0].Text); 
                        Topic topic = new Topic(); 
                        topic.LoadData(topicId); 
                        topic.Delete(); 
                        break; 
                    default: 
                        break; 
                } 
                Response.Redirect("TopicList.aspx"); 
            } 
    直接到这里了吖!~~
      

  4.   

    根本就没有
       public void GV_RowDeleting(Object sender, GridViewDeleteEventArgs e)
    触发这个!~~而是直接去判断case了
      

  5.   

    <asp:GridView ID="GV" runat="server"
             AutoGenerateColumns="false"
              AllowPaging="true"
               OnPageIndexChanging="GV_PageIndexChanging"
                OnRowDeleting="GV_RowDeleting"
                 PageSize="5"
                  OnRowCommand="GV_RowCommand" OnRowUpdating="GV_RowUpdating" Width="635px">
                  <Columns>
                  <asp:BoundField
                   DataField="TopicId"
                    HeaderText="编号" />
                    <asp:BoundField 
                    DataField="loginusername"
                     HeaderText="用户" />
                     <asp:BoundField DataField="Title"  
                     HeaderText="标题"/>
                     <asp:BoundField
                     DataField="CreateTime"
                     HeaderText="发表时间" />
                     <asp:ButtonField  Text="修改" 
                     HeaderText="修改"  
                     CommandName="Update"/>
                     <asp:HyperLinkField HeaderText="详细信息" 
                      DataNavigateUrlFormatString="TopicDetail.aspx?topic_id={0}"
                     text="详细信息"  
                     DataNavigateUrlFields="TopicId" 
                     DataTextFormatString="详细信息"/>
                     <asp:ButtonField
                      Text="删除" 
                      HeaderText="删除" 
                      CommandName="Delete" />
                  </Columns>这介是我的GV