e.Row.Cells[相关的列].HasControls()在调试的时候 永远都是false
我在第四个单元格添加料删除 和更新的
e.Row.Cells[2].HasControls()
false
e.Row.Cells[1].HasControls()
false
e.Row.Cells[0].HasControls()
false
e.Row.Cells[5].HasControls()
本来是用javascript添加客户端事件的 

解决方案 »

  1.   


    public partial class Admin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] != null || Session["userpwd"] != null)
            {
                string username = Convert.ToString(Session["username"]);
                string userpwd = Convert.ToString(Session["userpwd"]);
                if (Users.validateuser(username,userpwd))
                {
                    Label1.Text = username;
                }
                else
                {
                    Response.Redirect("login.aspx");
                }        }
            else
            {
                Response.Redirect("login.aspx");
            }
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.Cells[3].HasControls())
            {
                //LinkButton linkdelete =(LinkButton)e.Row.Cells[0].Controls[1];
                LinkButton linkupdate = (LinkButton)e.Row.Cells[0].Controls[0];
                if (linkupdate.Text.Equals("删除"))
                {
                linkupdate.Attributes.Add("onclick", "javascript:return confirm('" + string.Format("你确认要删除管理员{0}吗", DataBinder.Eval(e.Row.DataItem, "username")) + "')");
                }
            }
        }
    }
      

  2.   

    这个我知道 这个是绑定后发生的事件 我在gridview中 删除和操作都能实现但是现在我想加一些客户端时间 却无法获取控件的集合 就是row.cells[].control[]其中e.Row.Cells[相关的列].HasControls()在调试的时候 永远都是false
      

  3.   

    参考GridView 插入、删除、修改、分页的综合例子
    http://dotnet.aspx.cc/article/0e8fdeb4-c461-4f44-9933-672a7510097a/read.aspx
      

  4.   

    row.cells[].control[]是非模板列查找!
    Row.Cells[].FindControl[]是模板列查找!
    楼主是模板列还是非模板列??
      

  5.   

    汗,我一般都是这样写的
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
        (e.Row.FindControl["LinkButton1"] as LinkButton).Attributes.Add("onclick", "javascript:return confirm('" + string.Format("你确认要删除管理员{0}吗", DataBinder.Eval(e.Row.DataItem, "username")) + "')");
    }FindControl[里面是删除按钮的Id]
    只要判断那一列是不是数据行就可以了,如果是数据行就查找
      

  6.   

    if(GridView1.Row[e.RowIndex].Name=="LinkButton1")
      

  7.   

    刚才写错了
    dataGridView1.Columns[e.ColumnIndex].Name == "LinkButton1";