用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > Net教程

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

时间:2015-01-29  来源:互联网  作者:佚名
复制代码 代码如下:
 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;
                }
            }
        }
 
来顶一下
返回首页
返回首页
推荐资讯
解析WPF绑定层次结构数据的应用详解 解析WPF绑定层次结构数据的应用详解在实际项目应用中会存在多种类型的层次结构数据,WPF提供了良
基于.Net中的数字与日期格式化规则助记词的使用详解 基于.Net中的数字与日期格式化规则格式化可以通过string.Format方法或者直接使用xx.ToString(
相关文章
栏目更新
栏目热门