protected void grvw_timu_RowDataBound(object sender, GridViewRowEventArgs e)//显示符合条件的题目的GridView,显示行号 { if (e.Row.RowIndex != -1) { e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();//显示行号 string zuoyeid = Request.QueryString["zuoyeid"]; //设置添加和删除按钮的可用状态 int rowindex = e.Row.RowIndex; //然后根据行号,来得到主键 string questionid = grvw_timu.DataKeys[rowindex].Value.ToString(); Button tianjiabtn = (Button)(e.Row.FindControl("btn_add")); //添加按钮 Button shanchubtn = (Button)(e.Row.FindControl("btn_del")); //删除按钮 if (ZuoyeInfo.IsTimuInZuoye(zuoyeid, questionid)) { tianjiabtn.Enabled = false; shanchubtn.Enabled = true; } else { tianjiabtn.Enabled = true; shanchubtn.Enabled = false; } } }