ASP.NET - freeze header - Asked By msakt on 22-May-12 06:43 AM

 i done freeze header for grid....but header show in first row...hide first row value....  
Neha Garg replied to msakt on 22-May-12 06:57 AM
hi see the below example... it will helps you

private void LoadButton_Click(objectsender, RoutedEventArgs e)

{

stringfileName = @"C:\junk\test.txt";

TextRangerange;

FileStreamfStream;

if(File.Exists(fileName))

{

range = new TextRange(RTB.Document.ContentStart, RTB.Document.ContentEnd);

fStream = new FileStream(fileName,FileMode.OpenOrCreate);

range.Load(fStream, DataFormats.Text );

fStream.Close();

}

}

Neha Garg replied to msakt on 22-May-12 07:04 AM
See the below example:

if (e.Row.RowType == DataControlRowType.DataRow) 
     {
    if (e.Row.RowIndex == 0)
    {
      ViewState["i"] = e.Row.RowIndex;
    }
  
    if (Convert.ToInt32(ViewState["i"].ToString()) == e.Row.RowIndex)
    {
  
      GridViewRow row = new GridViewRow(e.Row.RowIndex, 0, DataControlRowType.Header, DataControlRowState.Normal);
      TableCell cell = new TableCell();
      cell.BackColor = System.Drawing.Color.BurlyWood;
      cell.Controls.Add(new Label { Text = "header" }); //as needed        
      row.Cells.Add(cell);
  
      cell = new TableCell();
      cell.Controls.Add(new Label { Text = "Name" }); //as needed        
      row.Cells.Add(cell);
  
      cell = new TableCell();
      cell.Controls.Add(new Label { Text = "age" }); //as needed        
      row.Cells.Add(cell);
  
      cell = new TableCell();
      cell.Controls.Add(new Label { Text = "Email" }); //as needed        
      row.Cells.Add(cell);
      int cnt = Convert.ToInt32(ViewState["i"].ToString());
  
      Table tbl = (e.Row.Parent as Table);
  
      //tbl.Controls.AddAt(e.Row.RowIndex * cnt , row);
       tbl.Controls.AddAt(e.Row.RowIndex, row);         
  
      cnt = cnt + 4;
      ViewState["i"] = cnt.ToString();
  
    }
  
  }
dipa ahuja replied to msakt on 22-May-12 08:29 AM

<style type="text/css">
  .WrapperDiv
  {
    width800px;
    height400px;
    border1px solid black;
  }
  
  .WrapperDiv TH
  {
    positionrelative;
  }
  
  .WrapperDiv TR
  {
    /* Needed for IE */
    height0px;
  }
</style>
<script>
  function onLoad() {
 
    FreezeGridViewHeader('GridView1''WrapperDiv');
  }
</script>

http://weblogs.asp.net/dwahlin/archive/2007/07/31/freeze-asp-net-gridview-headers-by-creating-client-side-extenders.aspx