?
Solved

Scrolling

Posted on 2004-11-30
3
Medium Priority
?
387 Views
Last Modified: 2010-04-23
Hi,
I have a growing problem. I have VS2003 Web Application VB.Net using datagrid for data coming from SQL. Everyone must have scrolling no one wants paging. Everyone must have sorting.

The problem is the datagrid is getting longer and so I need to make the header "frozen" so the data at the bottom of the grid will display the header row. I have done this before by hiding the datagrid header and create a new header above the grid but that won't work this time because of the sorting.

Thanks for any help/suggestions
Donnie
0
Comment
Question by:Donnie4572
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 1000 total points
ID: 12710575
Check this. It is scrollable datagrid with frozen header

HTML.
The idea is to make separate header and put it between div tags. Datagrid set headder to none

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ScrollDG.aspx.vb" Inherits="TestEverything.ScrollDG" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>ScrollDG</title>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:Label id="Label1" runat="server" style="Z-INDEX: 103; LEFT: 112px; POSITION: absolute; TOP: 8px"
                        Font-Size="Large" Width="623px" Font-Bold="True" ForeColor="Red" BorderStyle="Solid">Example of scrollable datagrid with frozen header</asp:Label>
                  <asp:hyperlink id="Hyperlink2" style="Z-INDEX: 105; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
                        NavigateUrl="Controls.aspx">Controls</asp:hyperlink>
                  <br>
                  <br>
                  <br>
                  <br>
                  <div>
                        <table style="Z-INDEX: 101; LEFT: -9px; WIDTH: 707px; POSITION: relative; BORDER-COLLAPSE: collapse; HEIGHT: 26px"
                              cellSpacing="0" align="left" border="1">
                              <tr>
                                    <td align="center" width="195" bgColor="navy"><font face="Verdana" color="white" size="4"><b>YYYYMM
                                                </b></font>
                                    </td>
                                    <td align="center" width="195" bgColor="navy" style="WIDTH: 195px"><font face="Verdana" color="white" size="4"><b>Prod
                                                      ID</b></font>
                                    </td>
                                    <td align="center" width="300" bgColor="navy"><font face="Verdana" color="white" size="4"><b>Name</b></font>
                                    </td>
                              </tr>
                        </table>
                  </div>
                  <div style="Z-INDEX: 102; LEFT: 2px; VERTICAL-ALIGN: top; OVERFLOW: auto; WIDTH: 710px; POSITION: absolute; TOP: 100px; HEIGHT: 300px">
                        <asp:datagrid id="dg" runat="server" ShowHeader="False" AutoGenerateColumns="False" BorderColor="Black"
                              BorderWidth="1px">
                              <Columns>
                                    <asp:BoundColumn DataField="YYYYMM" HeaderText="YYYYMM">
                                          <ItemStyle HorizontalAlign="Center" Width="200px"></ItemStyle>
                                    </asp:BoundColumn>
                                    <asp:BoundColumn DataField="ProdID" HeaderText="ProdID">
                                          <ItemStyle HorizontalAlign="Center" Width="200px"></ItemStyle>
                                    </asp:BoundColumn>
                                    <asp:BoundColumn DataField="Name" HeaderText="Name">
                                          <ItemStyle HorizontalAlign="Center" Width="300px"></ItemStyle>
                                    </asp:BoundColumn>
                              </Columns>
                        </asp:datagrid></div>
            </form>
      </body>
</HTML>

=============================================
Code behind

Imports System.Data.OleDb

Public Class ScrollDG
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents dg As System.Web.UI.WebControls.DataGrid
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Hyperlink2 As System.Web.UI.WebControls.HyperLink

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region
    Dim ds As New DataSet
   
    Dim fsConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
             "Data Source=C:\TestDB\TestDB.mdb;"
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        FillDataSet()
        dg.DataSource = ds
        dg.DataBind()
    End Sub
    Sub FillDataSet()
        Dim sSQL As String
        sSQL = "select YYYYMM, ProdID, Name from PRQ"

        Dim cn As New OleDbConnection(fsConn)
        cn.Open()
        ' Fill the dataset ds
        Dim da As New OleDbDataAdapter(sSQL, cn)
        da.Fill(ds)
        cn.Close()
    End Sub

End Class
0
 
LVL 12

Author Comment

by:Donnie4572
ID: 12719081
Thanks,
This is works for scrolling...frozen header. I don't see how to fit sorting into the code.

Im using the sortcommand event to sort which fires from the column header.

Private Sub mydatagrid_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles mydatagrid.SortCommand
        mydatagrid.DataSource = mydataset1.mytable.DefaultView
        mydataset1.mytable.DefaultView.Sort = e.SortExpression
        mydatagrid.DataBind()

    End Sub

Thanks,
Donnie
0
 
LVL 12

Author Comment

by:Donnie4572
ID: 12768263
Any More Ideas?
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question