DATAVIEW的rowcommand事件获取主键

   protected void GV_Teauditing_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                ((Button)e.Row.FindControl("btn1")).Attributes.Add("onclick", "javascript:return confirm('你确认要通過審核吗?')");
            }

        }
        Button btn1 = (Button)e.Row.FindControl("btn1");
        if (btn1 != null)
        {
            btn1.CommandArgument = e.Row.RowIndex.ToString();
        }
    }


protected void GV_Teauditing_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Check")
        {
            //int index=Convert.ToInt16(e.CommandArgument);
            //DataKey key = GV_Teauditing.DataKeys[index];
            //string SN =Convert.ToString( key.Value);
            //string SN = GV_Teauditing.DataKeys["SN"].ToString();
            try
            {

                int index = Convert.ToInt32(e.CommandArgument);
                string SN = GV_Teauditing.DataKeys[index].Value.ToString();
                //string SN = GV_Teauditing.DataKeys[e].Value.ToString();
                string teamNO = MySqlBase.GetVarFromSql("Com_GetNoByDate", "datestr");
                string auditPeo = LoginUser.CName;
                DateTime effDate = DateTime.Now;
                SqlParameter[] p = new SqlParameter[4];
                p[0] = new SqlParameter("@SN", SN);
                p[1] = new SqlParameter("@teamNO", teamNO);
                p[2] = new SqlParameter("@auditPeo", auditPeo);
                p[3] = new SqlParameter("effDate", effDate);
                int i = MySqlBase.ExecuteSql("Team_auditing_up", p);
                BindGrid();
            }
            catch (Exception Err)
            {
                string tErr = Err.Message;
            }
        }
    }

posted @ 2008-07-11 16:21  XGU_Winner  阅读(432)  评论(0编辑  收藏  举报