How to dynamically set whether CommandField is available or visible in GridView
This article mainly introduces how to dynamically set whether CommandField is available or visible in GridView, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The code is as follows:
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 / / make editing functions available under certain conditions
{
Price = ((TextBox) e.Row.Cells [4] .controls [0]) .Used when editing the Text;// point
}
Catch
{
Price = e.Row.Cells [4] .Text; / / for use at the beginning
}
If (price = "" | | price = = "")
{
E.Row.Cells [7] .controls [0] .visible = false
}
Else
{
E.Row.Cells [7] .controls [0] .visible = true
}
}
}
Thank you for reading this article carefully. I hope the article "how to dynamically set whether CommandField is available or visible in GridView" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!