protected void myGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string id;
        id = myGridView.Rows[int.Parse(e.CommandArgument.ToString())].Cells[0].Text;
        switch (e.CommandName)
        {
            case "Delete":
                whb147.BLL.USER_LEVEL bll = new whb147.BLL.USER_LEVEL();
                bll.Delete(int.Parse(id));
                break;
            case "Edit":
                Response.Redirect("User_Info_Edit.aspx?ID=" + id);
                break;
            case "View":
                Response.Redirect("User_Info_View.aspx?ID=" + id);
                break;
            default:
                break;
        }
    }

解决方案 »

  1.   

    TO:whb147(苦乐随缘) 您的方法不行~~~~~
      

  2.   

    在GridView1_RowDataBound事件写
      LinkButton linkBtn= e.Row.FindControl("LinkButton1") as LinkButton;
           if (linkBtn != null)
           {
               linkBtn.CommandName = "TT";
           }
    在GridView1_RowCommand事件写
     if (e.CommandName == "TT")
            {
              //执行操作
                Response.Write("Yes");
            }~~~~~~~~~~~接分~~~~~~~~~~~~~~~~
      

  3.   

    TO:liusen5555() ,您的方法跟我的一样
    如果是模板列那这样写是可以的,但是我是手动添加linkbutton控件
      

  4.   

    GridView1_RowDataBound1在这里写
    LinkButton glbt = new LinkButton();
    glbt.Text = e.Row.Cells[1].Text;
    e.Row.Cells[1].Controls.AddAt(0, glbt);
    glbt.CommandName = "gridlist";
    在RowCreated中写试试
      

  5.   

    动态添加的控件在点击的时候状态就丢失了..如果想保存状态..需要每次在pageLoad事件里都加载你的那个控件才行的...
      

  6.   

    既然你每行都要LinkButton,为何不直接先拖控件出来呢,只要给赋值Text就好了啊
      

  7.   

    试试在RowCreated中把LinkButton创建出来,并指定CommandName 然后在RowDataBound给LinkButton的TEXT赋值
      

  8.   

    protected void gvwContract_RowCommand(object sender, GridViewCommandEventArgs e)
          {
                int index = Convert.ToInt32(e.CommandArgument);
                int objid = Convert.ToInt32(gvwContract.DataKeys[index].Value);
                string url;
                url = "ContractDocs.aspx?objectid=" + objid;
                Response.Redirect(url);            //Response .Redirect ("ContractDocs.aspx?objectid="+objid )
          }
          protected void gvwContract_RowCreated(object sender, GridViewRowEventArgs e)
          {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                      LinkButton LinkButton1 = (LinkButton)e.Row.FindControl("LinkButton1");
                      LinkButton1.CommandArgument = e.Row.RowIndex.ToString();
                }
          }
      

  9.   

    检查linkbutton的click事件名称是否和你写的事件名称一致