Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi,
How can I hide a TemplateField column in a GridView
my cose in markup:
ASP.NET
<asp:TemplateField ShowHeader='<%# CheckStatus(Bind("Status")) %>' >
</asp:TemplateField>



in code behinde:
C#
public static bool CheckStatus(object Status)
       {
           if (Status.ToString() == "4")
               return false;
           else
               return true;
       }

i try above code but get error:
C#
Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.TemplateField does not have a DataBinding event.



thanks
Posted
Updated 27-Feb-18 6:47am

<asp:TemplateField ShowHeader='<%# Bind("Status") == 4 ? true : false %>' >
</asp:TemplateField>
 
Share this answer
 
Comments
Richard Deeming 27-Feb-18 14:13pm    
This question was asked, answered, and solved FIVE YEARS AGO.

And your "solution" suffers from the same problem as the code in the question.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[2].Visible = false;//this is your templatefield column.
}
}
 
Share this answer
 
Try:

C#
GridView1.Columns[1].Visible = false; 
 
Share this answer
 
Comments
Member 10492256 16-Dec-14 5:58am    
Solution 2 helps me.,.
Its running absolutely what i wanted.,.
thank you priyanka7777.,. :)
SathishRam 31-Dec-14 6:42am    
Tan Q !!!!! Priyanka7777
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900