日期:2014-05-18  浏览次数:20375 次

在GridView中 有没有好的方法根据rows中某个字段值确定它可不可以编辑同删除
如GridView表:
  编辑       序号       班级       学号           学科       分数     删除
  编辑       1             306         22898         9             119       删除
  编辑       2             306         22898         8             139       删除
  编辑       3             306         22898         6             107       删除  
  编辑       4             306         22898         7             110       删除  
  编辑       5             306         22898         5             98         删除  
  编辑       6             306         22898         1             121       删除  

那么我要规定在学科为1的记录不能删除

如何做最好

有啥好的设置方法     大家帮忙




------解决方案--------------------
删除事件里判断一下不就可以了?
------解决方案--------------------
楼上正解. case 后面加个break;就可.
------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > = 0)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

Label lbQty = e.Row.Cells[6].FindControl( "lb_Qty ") as Label;
Label lbSet = e.Row.Cells[7].FindControl( "lb_Set ") as Label;

int qty = 0;
int set = 0;
if (lbQty != null && (lbQty.Text.Trim() != " " || lbQty.Text.Trim() != string.Empty) && lbSet != null && (lbSet.Text.Trim() != " " || lbSet.Text.Trim() != string.Empty))
{
qty = Convert.ToInt32(lbQty.Text.Trim());
set = Convert.ToInt32(lbSet.Text.Trim());

if (qty < set)
{
e.Row.BackColor = System.Drawing.Color.Red;
btnChange.Enabled = false;
}
}
else
{
btnChange.Enabled = false;
}


}
}
}
------解决方案--------------------
再RowDataBound事件内判断条件就可以了,
------解决方案--------------------
1.
方法 1 同 sosohehe

2。
方法 2 如下:

<asp:templatefield>
<itemtemplate>