欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

GridView中动态设置CommandField是否可用或可见的小例子

程序员文章站 2024-03-02 23:35:16
复制代码 代码如下: protected void gvmaterial_rowdatabound(object sender, gridviewrowevent...
复制代码 代码如下:

 protected void gvmaterial_rowdatabound(object sender, gridviewroweventargs e)
        {
            if (e.row.rowtype == datacontrolrowtype.datarow || e.row.rowtype == datacontrolrowtype.header)
            {
                e.row.cells[0].visible = false;

            }
            if (e.row.rowtype == datacontrolrowtype.datarow)
            {
                e.row.cells[1].text = (gvmaterial.pageindex * gvmaterial.pagesize + e.row.rowindex + 1).tostring();
                string price;
                try //让编辑功能在特定条件下可以用
                {
                     price = ((textbox)e.row.cells[4].controls[0]).text;//点编辑的时候用
                }
                catch
                {
                     price = e.row.cells[4].text;    //出始时用
                }                         
                if (price == "" || price == " ")
                {
                    e.row.cells[7].controls[0].visible = false;
                }
                else
                {
                    e.row.cells[7].controls[0].visible = true;
                }
            }
        }