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

编程学习 2021-07-04 22:40www.dzhlxh.cn编程入门
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 © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板