Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. Gridview with fixed row

Gridview with fixed row

Scheduled Pinned Locked Moved IT & Infrastructure
cssdatabasetutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kyi kyi
    wrote on last edited by
    #1

    Hi i would like to display a gridview with "10"rows(including header row) .it's fixed.i m populating the girdview with the data from dataTable(that returns from particular query). e.g if the datatable has no row, it will show blank gridview . if the datatale has 2 rows, gridview will show these 2 rows and other rows are blank. and grid view also must have vertical scroll bar. now it can disply only the return data . i m still trying. could any body guide me please? thanks in advance!

    Steve EcholsS J 2 Replies Last reply
    0
    • K kyi kyi

      Hi i would like to display a gridview with "10"rows(including header row) .it's fixed.i m populating the girdview with the data from dataTable(that returns from particular query). e.g if the datatable has no row, it will show blank gridview . if the datatale has 2 rows, gridview will show these 2 rows and other rows are blank. and grid view also must have vertical scroll bar. now it can disply only the return data . i m still trying. could any body guide me please? thanks in advance!

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      Could just add some extra rows to your datatable before binding.

      for(int i = yourDataTable.Rows.Count; i < 10; i++)
      {
      DataRow blankRow = yourDataTable.NewRow();
      // could set row values here if you wanted to
      yourDataTable.Rows.Add(blankRow);
      }

      yourGridView.DataSource = yourDataTable;
      yourGridView.DataBind();

      As far as vertical scroll bar, now you're into styling. You could put your grid view in a div with style="overflow: auto; height: 100px;", or something like that. If you want to have just the data scroll, and the headers remain fixed, then it's a ton of work. You'll need two tables (grid views), one for the header one for the data, then apply above styles to just the data grid view and turn of headers for the data grid view. Hope that leads you in the right direction.


      - S 50 cups of coffee and you know it's on! A post a day, keeps the white coats away!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      1 Reply Last reply
      0
      • K kyi kyi

        Hi i would like to display a gridview with "10"rows(including header row) .it's fixed.i m populating the girdview with the data from dataTable(that returns from particular query). e.g if the datatable has no row, it will show blank gridview . if the datatale has 2 rows, gridview will show these 2 rows and other rows are blank. and grid view also must have vertical scroll bar. now it can disply only the return data . i m still trying. could any body guide me please? thanks in advance!

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #3

        Here's another way of doing it:

        Private Sub DG_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles DG.PreRender
        Dim DG As DataGrid = CType(sender, DataGrid)
        Dim Tbl As Table = CType(DG.Controls(0), Table)
        For i = 0 To _NumberOfRowsToAdd - 1
        Tbl.Controls.Add(AddEmptyRow)
        Next i
        End Sub

        Function AddEmptyRow() As DataGridItem
        Dim DGI As DataGridItem = New DataGridItem(0, 0, ListItemType.Item)
        Dim cell As New TableCell
        cell.ColumnSpan = _NumberOfColumns
        cell.Text = " "
        DGI.Cells.Add(cell)
        Return DGI
        End Function

        When you create your Datatable you will need to populate two fields with the number of columns and rows to add to the datagrid.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups