How to hide a TemplateField column in a GridView

前端 未结 9 1848
遇见更好的自我
遇见更好的自我 2020-12-03 04:13

How can I hide a TemplateField column in a GridView?

I tried the following:



        
9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 04:54

    protected void gvLogMessageDetail_RowDataBound(object sender, GridViewRowEventArgs e)  
        { 
          if (e.Row.RowType == DataControlRowType.Header)   
            {  
                if (rdlForImportOrExport.SelectedIndex == 1)  
                {  
                    e.Row.Cells[3].Visible = false;  
                    e.Row.Cells[4].Visible = false;  
                    e.Row.Cells[5].Visible = false;  
                }  
                else  
                {  
                    e.Row.Cells[3].Visible = true;  
                    e.Row.Cells[4].Visible = true;  
                    e.Row.Cells[5].Visible = true;  
                }  
            }    
            if (e.Row.RowType == DataControlRowType.DataRow) //skip header row  
            {  
                try  
                {  
                    if (rdlForImportOrExport.SelectedIndex == 1)  
                    {  
                        e.Row.Cells[3].Visible = false;  
                        e.Row.Cells[4].Visible = false;  
                        e.Row.Cells[5].Visible = false;  
                    }  
                    else  
                    {  
                        e.Row.Cells[3].Visible = true;  
                        e.Row.Cells[4].Visible = true;  
                        e.Row.Cells[5].Visible = true;  
                    }  
                    }  
                catch  
                {  
                    ClientScript.RegisterStartupScript(GetType(), "Expand", "");  
                }  
            }  
        }  
    

提交回复
热议问题