How to hide columns in an ASP.NET GridView with auto-generated columns?

前端 未结 12 1689
陌清茗
陌清茗 2020-11-30 08:28

GridView1.Columns.Count is always zero even SqlDataSource1.DataBind();

But Grid is ok

I can do

for (int i = 0; i < GridView1.HeaderRow.Cel         


        
12条回答
  •  心在旅途
    2020-11-30 09:07

    Note: This solution only works if your GridView columns are known ahead of time.

    It sounds like you're using a GridView with AutoGenerateColumns=true, which is the default. I recommend setting AutoGenerateColumns=false and adding the columns manually:

    
        
            
            
            
        
    
    

    And only include a BoundField for each field that you want to be displayed. This will give you the most flexibility in terms of how the data gets displayed.

提交回复
热议问题