如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的记录不能删除如何做最好有啥好的设置方法  大家帮忙

解决方案 »

  1.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
    string temp=e.Row.Cells[4].Text.Trim();
    switch(temp)
    {
     case "1": e.Row.Cells[6].Enabled=false;
    }
    }
    }
      

  2.   

    楼上正解.
    case 后面加个break;就可.
      

  3.   

    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;
                        }
                                         }
                }
            }
      

  4.   

    再RowDataBound事件内判断条件就可以了,
      

  5.   

    1.
    方法 1 同 sosohehe2。
    方法 2 如下:<asp:templatefield>
    <itemtemplate>
    <asp:linkbutton id=btnDelete commandname=delete enabled='<%# (int)Eval("学科") != 1 %>'
    </itemtemplate>
    </asp:templatefield>
      

  6.   

    if ((HyperLink)e.Row.FindControl("hyperlink") != null)
            {
                if (e.Row.Cells[15].Text == "待收货")
                {
                    ((HyperLink)e.Row.FindControl("hyperlink")).Text = "<a color='#333333'>待收货</a>";
                }
                else if(e.Row.Cells[15].Text == "已入库")
                {
                    ((HyperLink)e.Row.FindControl("hyperlink")).Text = "<a><font color='#000FFF'>已入库</font></a>";
                }
                else
                {
                    ((HyperLink)e.Row.FindControl("hyperlink")).Text = "<Font color='red'>已收货</Font>";
                    ((HyperLink)e.Row.FindControl("hyperlink")).NavigateUrl = "Javascript:launchmodule(600,450,'../AssetApply4/Asset_InsertDevices.aspx?OrderListID="+e.Row.Cells[1].Text+"',0,0,0)";
                }
            }  if ((HyperLink)e.Row.FindControl("hyperlink") != null)
            {
                if (e.Row.Cells[15].Text == "待收货")
                {
                    ((HyperLink)e.Row.FindControl("hyperlink")).Text = "<a color='#333333'>待收货</a>";
                }
                else if(e.Row.Cells[15].Text == "已入库")
                {
                    ((HyperLink)e.Row.FindControl("hyperlink")).Text = "<a><font color='#000FFF'>已入库</font></a>";
                }
                else
                {
                    ((HyperLink)e.Row.FindControl("hyperlink")).Text = "<Font color='red'>已收货</Font>";
                    ((HyperLink)e.Row.FindControl("hyperlink")).NavigateUrl = "Javascript:launchmodule(600,450,'../AssetApply4/Asset_InsertDevices.aspx?OrderListID="+e.Row.Cells[1].Text+"',0,0,0)";
                }
            }
      

  7.   

    在ItemDataBound事件中判断~
    Jinglecat(晓风残月 >> 问题需简洁,错误要详细)的方法也可以
      

  8.   

    最简便的方式:在删除或编辑前,判断学科是否为"1":
    if (dataGridView.Rows[e.RowIndex].Cells["学科"].Value.ToString().Trim() != "1")
    {
       // 不为"1",删除或编辑
    }