Hi,
Even if one row has value for attachment, the Attachment column has to be visible right?
In that case, this solution should help you.
Make the Attachment column hidden by default and if any of the row has value for attachment, then make Attachment column visible.
Add these two classes to CSS file and reference that to the page.
.hideGridColumn
{
display:none;
}
.showGridColumn
{
display:inline;
}
Change the column definition like below:
<asp:BoundField DataField="Attachment" ItemStyle-CssClass="hideGridColumn" HeaderStyle-CssClass="hideGridColumn" HeaderText="Attachment"/>
In the GridView1_RowDataBound, check for existence of value and make the column visible if value is present. Assuming the cell index for attachment column as 10 based on the code provided in question.
protected void gvChangeColor_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
bool makeVisible = false;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (!string.IsNullOrEmpty(e.Row.Cells[10].Text) && e.Row.Cells[10].Text != " ")
{
makeVisible = true;
}
}
if (makeVisible)
{
gvChangeColor.HeaderRow.Cells[10].CssClass = "showGridColumn";
gvChangeColor.Columns[10].ItemStyle.CssClass = "showGridColumn";
}
}
catch (Exception ex)
{
string msg = ex.Message;
}
}