locked
Fix Gridview Header On Scroll RRS feed

  • Question

  • User-807418713 posted

    Hello

    I Used this below code

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
      <title>Bootstrap 101 Template</title>
    
      <!-- Bootstrap -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
      <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
      <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    
    <body>
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <div class="table-responsive">
              <asp:GridView ID="grdPDFView" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-condensed">
                <Columns>
                  <asp:TemplateField HeaderText="Files1">
                    <ItemTemplate>
                    </ItemTemplate>
                  </asp:TemplateField>
    
     <asp:TemplateField HeaderText="Files2">
                    <ItemTemplate>
                    </ItemTemplate>
                  </asp:TemplateField>
    
    
     <asp:TemplateField HeaderText="Files3">
                    <ItemTemplate>
                    </ItemTemplate>
                  </asp:TemplateField>
    
    
    
                </Columns>
              </asp:GridView>
            </div>
          </div>
        </div>
      </div>
    
      <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <!-- Include all compiled plugins (below), or include individual files as needed -->
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </body>
    
    </html>

    I want to set fix header how to do so

    Monday, September 9, 2019 7:01 PM

Answers

  • User288213138 posted

    Hi Gopi.MCA,

    <asp:GridView ID="grdPDFView"

    In the html page,  the browser does not render asp tags.

    So if you want to fix Gridview Header, I suggest you can do it in the web form.

    You can try to use ScrollableGridView plugin.

    The code:

    <script src="ScrollableGridPlugin_ASP.NetAJAX_2.0.js"></script>
    <script>
            $(document).ready(function () {
                $('#<%=GridView1.ClientID %>').Scrollable({
                    ScrollHeight: 300,
                    Width: 467
                });
            });
    </script>
    <div class="container">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="table-responsive">
                                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                                    <Columns>
                                        <asp:TemplateField HeaderText="CustomerId">
                                            <ItemTemplate>
                                                <%# Eval("CustomerId") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Name">
                                            <ItemTemplate>
                                                <%# Eval("Name") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Country">
                                            <ItemTemplate>
                                                <%# Eval("Country") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </div>
                        </div>
                    </div>
                </div>
    
    

    The result:

    If you don't want to use plug, you can use javascript to fix the Gridview header.

    Dynamically freeze ASP.Net Gridview header using JavaScript

    If you want to construct a Gridview in an HTML page and fix its header, you can refer to this link:

    https://forums.asp.net/t/2154515.aspx

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 10, 2019 2:38 AM