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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-18 我要评论
想了解GridView中动态设置CommandField是否可用或可见的小例子的相关内容吗,在本文为您仔细讲解动态设置CommandField的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:GridView,CommandField,下面大家一起来学习吧。
复制代码 代码如下:

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们