abdujalil  chuliev

abdujalil chuliev

  • 1.2k
  • 400
  • 38.8k

how to hide null cell before rotating GridView

Jun 15 2017 1:51 AM
I want my GridView to hide the column which has null row value then rotate. I have some code below. But it is checking value after rotating. There is only one selected row and many columns.
 
  1. protected void btnSearch_Click(object sender, EventArgs e)  
  2.     {  
  3.         gvDb.DataSource = (c());  
  4.         gvDb.DataBind();  
  5.         hideNull();  
  6.     }  
  7.   
  8.     public DataSet c()  
  9.     {  
  10.         SqlConnection cn = new SqlConnection(cs);  
  11.         cn.Open();  
  12.         SqlDataAdapter ad = new SqlDataAdapter("select * from DESIGNSTABLE WHERE B210_APPL_NUMBER=" + txtID.Text + "", cn);  
  13.         DataSet ds = new DataSet();          
  14.         ad.Fill(ds, "DB");          
  15.         gvDb.DataSource = ds;  
  16.         gvDb.DataBind();          
  17.         cn.Close();  
  18.         return ds;  
  19.     }  
  20.   
  21.     public DataSet FlipDataSet(DataSet my_DataSet)  
  22.     {  
  23.         DataSet ds = new DataSet();  
  24.         foreach (DataTable dt in my_DataSet.Tables)  
  25.         {  
  26.             DataTable table = new DataTable();  
  27.             for (int i = 0; i <= dt.Rows.Count; i++)  
  28.             {  
  29.                 table.Columns.Add(Convert.ToString(i));  
  30.             }  
  31.             DataRow r = null;  
  32.             for (int k = 0; k < dt.Columns.Count; k++)  
  33.             {  
  34.                 r = table.NewRow();  
  35.                 r[0] = dt.Columns[k].ToString();  
  36.                 for (int j = 1; j <= dt.Rows.Count; j++)  
  37.                     r[j] = dt.Rows[j - 1][k];  
  38.                 table.Rows.Add(r);  
  39.             }  
  40.             ds.Tables.Add(table);  
  41.         }  
  42.         return ds;  
  43.     }      
  44.     protected void hideNull()  
  45.     {  
  46.         Boolean hasData = false;  
  47.   
  48.         for (int col = 0; col < gvDb.HeaderRow.Cells.Count; col++)  
  49.         {  
  50.             for (int row = 0; row < gvDb.Rows.Count; row++)  
  51.             {  
  52.                 if (!String.IsNullOrEmpty(gvDb.Rows[row].Cells[col].Text)  
  53.                     && !String.IsNullOrEmpty(HttpUtility.HtmlDecode(gvDb.Rows[row].Cells[col].Text).Trim()))  
  54.                 {  
  55.                     hasData = true;  
  56.                     break;  
  57.                 }  
  58.             }  
  59.             if (!hasData)  
  60.             {  
  61.                 gvDb.HeaderRow.Cells[col].Visible = false;  
  62.                 for (int hiddenrows = 0; hiddenrows < gvDb.Rows.Count; hiddenrows++)  
  63.                 {  
  64.                     gvDb.Rows[hiddenrows].Cells[col].Visible = false;  
  65.                 }  
  66.             }  
  67.             hasData = false;  
  68.         }  
  69.     }  

Answers (1)