GridView中动态设置CommandField是否可用或可见的小例子
2019/7/7 18:30:45
本文主要是介绍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;
}
}
}
这篇关于GridView中动态设置CommandField是否可用或可见的小例子的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!