在gridview中添加列checkboxfield,并把该列转化为模板列。
现在问题是:我如何在checkbox的CheckedChanged(选中状态改变事件)中获得该box所在行,因为我要编辑该行的信息。
甚至还不知道如何获得这个checkbox对象。
我不知道我表达清楚了没有,请知道的帮帮忙,谢谢。

解决方案 »

  1.   

    不想要逐行遍历的做法,因为我的gridview可能有很多行,遍历效率太低
      

  2.   

    可能用命令名来看吧,自已加的命令的话。if (gvPCInfo.Rows.Count > 0 && times==1)
                {
                    for (int i = 0; i < gvPCInfo.Rows.Count; i++)
                    {
                        if (((LinkButton)gvPCInfo.Rows[i].Cells[1].Controls[2]).Text == acc.GetSearLable("Delete", 1))
                        {
                            gvPCInfo.Rows[i].Cells[0].Text = (gvPCInfo.Rows[i].RowIndex + 1).ToString();//NO                        LinkButton link = (LinkButton)gvPCInfo.Rows[i].Cells[1].Controls[2];
                            link.CommandName = "DelRow";
                            link.Attributes["onclick "] = "return   confirm( '您确定要删除吗? '); ";
                            // lbtDelTop.Attributes.Add( "onclick ", "return   confirm( '您确定要删除吗? '); "); 
                        }
                    }
                } try
            {
                if (e.CommandName == "DelRow")
                {
                    int rowsinx = Convert.ToInt16(e.CommandArgument.ToString());
                    
                    string PCNO = gvPCInfo.Rows[rowsinx].Cells[2].Text.Trim();
                    string sqlstr = "DELETE FROM [dbo].[ITItem_ComputerInfo]" +
              "WHERE PCNO='" + PCNO + "'";
                    UpdateEntry(sqlstr);
                    getbingdata();
                    setgvcol(1);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
      

  3.   

    第二个是写在gvpcEntry_RowCommand事件中