各位大侠,帮我看看,到底是什么状况..
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                OnRowDataBound="GridView1_RowDataBound" 
                OnPageIndexChanging="GridView1_PageIndexChanging" 
                OnRowDeleting="GridView1_RowDeleting"
                OnRowCancelingEdit="GridView1_RowCancelingEdit" 
                OnRowEditing="GridView1_RowEditing" 
                OnRowUpdating="GridView1_RowUpdating" AutoGenerateColumns="False">
                    <Columns>
                    <asp:BoundField DataField="ClassifyID" HeaderText="一级主码"  ReadOnly="True">
                    <ItemStyle Width="18%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="ParentID" HeaderText="二级子码" >
                    <ItemStyle Width="18%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="ClassifyName" HeaderText="图块类别">
                    <ItemStyle Width="18%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="ClassifyMark" HeaderText="分值" >
                    <ItemStyle Width="18%" />
                    </asp:BoundField>
                    <asp:CommandField HeaderText="编辑" ShowEditButton="True">
                    <ItemStyle Width="18%" />
                    </asp:CommandField>
                    <asp:CommandField HeaderText="删除" ShowDeleteButton="True"><ItemStyle width="10%" /></asp:CommandField>
                    </Columns>
cs:
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
     }public void Bind()
    {
        string strsqlcode;        strsqlcode = "select ClassifyID ,ParentID ,ClassifyName ,ClassifyMark from Gallery_Dwg_Dir";
        conn = new SqlConnection(strcon);
        conn.Open();
        SqlDataAdapter dpart = new SqlDataAdapter(strsqlcode, conn);
        DataSet dset = new DataSet();
        dpart.Fill(dset);
        GridView1.DataSource = dset.Tables[0];
        GridView1.DataBind();
        GridView1.DataKeyNames = new string[] { "ClassifyID" };
        conn.Close();
    }    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();
    }    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string strclsyid = GridView1.DataKeys[e.RowIndex].Value.ToString().Trim();
        string strdelcode = "delete from Gallery_Dwg_Dir where ClassifyID=" + strclsyid + "";
        conn = new SqlConnection(strcon);
        cmd = new SqlCommand(strdelcode, conn);
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
        Bind();
    }    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if ((e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)) || (e.Row.RowState == DataControlRowState.Edit))
        {
            TextBox curText;
            for (int i = 1; i < 4; i++)
            {
                curText = (TextBox)e.Row.Cells[i].Controls[0];
                curText.Width = Unit.Pixel(80);
            }
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate && e.Row.RowState != DataControlRowState.Edit)
            {
                ((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "javascript:return confirm('确定删除?')");
            }
        }
    }    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        Bind();
    }    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        Bind();
    }    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string strParentID;
        GridViewRow row = GridView1.Rows[e.RowIndex];
        if (((TextBox)(row.Cells[2].Controls[0])).Text.ToString().Trim() == "")
        {
            strParentID = "0";
        }
        else
        {
            strParentID = ((TextBox)(row.Cells[2].Controls[0])).Text.ToString().Trim();
        }
        string strsqlupdate = "update Gallery_Dwg_Dir set ParentID='" + strParentID + "',
        ClassifyName='" + ((TextBox)(row.Cells[3].Controls[0])).Text.ToString().Trim() + "',
        ClassifyMark='" + ((TextBox)(row.Cells[4].Controls[0])).Text.ToString().Trim() + "' 
        where ClassifyID='" + GridView1.DataKeys[e.RowIndex].Value.ToString().Trim() + "'";
        try
        {
            conn = new SqlConnection(strcon);
            cmd = new SqlCommand(strsqlupdate, conn);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
            GridView1.EditIndex = -1;
            Bind();
        }
        catch (Exception err)
        {
            Response.Write(err.Message);
        }
    }
除了“更新”按钮点下去,一点反应也没有(GridView1_RowUpdating(),都不执行),别的都可以正常使用

解决方案 »

  1.   

     GridView属性加DataKeyNames="主键" 
      

  2.   


    public void Bind() 
        { 
            string strsqlcode;         strsqlcode = "select ClassifyID ,ParentID ,ClassifyName ,ClassifyMark from Gallery_Dwg_Dir"; 
            conn = new SqlConnection(strcon); 
            conn.Open(); 
            SqlDataAdapter dpart = new SqlDataAdapter(strsqlcode, conn); 
            DataSet dset = new DataSet(); 
            dpart.Fill(dset); 
            GridView1.DataSource = dset.Tables[0]; 
            GridView1.DataBind(); 
            GridView1.DataKeyNames = new string[] { "ClassifyID" }; 
            conn.Close(); 
        } 我上面是这样写的   应该怎么改么?
      

  3.   

    我也想调试啊,问题是  不管哪个做断点,点更新,都没动静    感觉就像,没给OnRowUpdating事件写代码一样  protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) 
    根本没执行
      

  4.   

    你怎么调试的。
    我没用过RowUpdating事件.
    如果你调试正常就说明这个事件对UPDATE不起作用。
    否则的话你调试方式错了,不太可能吧
      

  5.   

    好吧,我这样说吧:
    我把这句删了  OnRowUpdating="GridView1_RowUpdating"  ,就是说,更新,按钮事件没定义。点击“更新”按钮也不会出错,就是没反应
      

  6.   

     OnRowUpdating="GridView1_RowUpdating"这句删了?有反映才怪。还是调试吧
      

  7.   

    GridView“GridView1”激发了未处理的事件“RowUpdating”。  这应该是必须出现的啊??
    如果,都没有错误,我都不知道怎么调试了你教我下    我学asp.net 不久,都不怎么懂
      

  8.   

    GridView1这控件我也用的不熟。。
    静待高人吧
      

  9.   

    NND  终于,弄出来了
    经过,把里面的控件 一个个,排除。
    终于发现,导致更新按钮的脚本不执行的原因是与“RequiredFieldValidator”验证脚本冲突