Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can hide my gridviews column on page load , but i dont want to use its column index to hide .. there is other method which uses column name to hide the column .. datakey or something like that ... plese help me
Posted

Try this:
C#
foreach (DataControlField col in gridView1.Columns)
            {
                if (col.HeaderText == "Name")
                {
                    col.Visible = false;
                }
            }
 
Share this answer
 
Comments
Torakami 18-Sep-13 7:02am    
hey prasad this alternative is nice .. there is one more which is very good even though.. I have forgotten now but even this one is worked for me .. thanks
Prasad_Kulkarni 18-Sep-13 7:09am    
Glad to hear!
You're welcome.
VICK 18-Sep-13 8:38am    
Sorry to disturb you Prasad.

Actually I have a question.. For example if i have a gridview containing some link button in it... and I want to show or hide that specific link on the basis of another column's value..

Can you give idea that how to do that???
Prasad_Kulkarni 18-Sep-13 8:46am    
Well, this is another question, you should ask a seperate one. For now, what you can do is something like this:
foreach (GridView item in gridView1.Rows)
{
if (item.SelectedRow.Cells[1].Text == "company1")
{
//Do not add your link button
}
else
{
//Add link button
}
}
VICK 18-Sep-13 8:54am    
U r right.. Any ways thanks alot.. I did the same in rowcreated event of gridview... :)

Will try this some other time.. Thanks.. Appreciated. :)
Hi

You can use like this
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs 
{
    e.Row.Cells[0].Visible = false;
}
 
Share this answer
 
Comments
Torakami 18-Sep-13 7:01am    
Why cant u c my question properly first .. I said i dont want to use index property

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