Gridview with fixed row
-
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!
-
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!
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!
-
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!
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 SubFunction 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 FunctionWhen you create your Datatable you will need to populate two fields with the number of columns and rows to add to the datagrid.