Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
using the script

Scrollable Gridview with fixed headers in asp.net - ASP.NET,C#.NET,MVC,JQuery,JavaScript,SQL Server,WCF examples[^]

work for one GridView

but for Two or more GridView ?

What I have tried:

the script for GrdView1

ScriptManager.RegisterStartupScript(Page, this.GetType(), "Key", "<script>MakeStaticHeader('" + GrdView1.ClientID + "', 400, 950 , 40 ,true); </script>", false);


in the case of a second gridview ? if I say another script
has no effect


ScriptManager.RegisterStartupScript(Page, this.GetType(), "Key", "<script>MakeStaticHeader('" + GrdView2.ClientID + "', 400, 950 , 40 ,true); </script>", false);
Posted
Updated 28-Jan-19 21:10pm
Comments
Richard MacCutchan 27-Jan-19 12:17pm    
You should ask at the site where you obtained the code.
Richard Deeming 28-Jan-19 7:48am    
Did you remember to change the "Key" parameter for the second RegisterStartupScript call?

1 solution

it is not enough to change the key to have another GridView


First call -- work
ScriptManager.RegisterStartupScript(Page, this.GetType(), "Grd2", "<script>MakeStaticHeader('" + GridView2.ClientID + "', 450, 850 , 22 ,false); </script>", false);

other GridView with the new Key -- variable already decalred
ScriptManager.RegisterStartupScript(Page, this.GetType(), "Grd1", "<script>MakeStaticHeader('" + GridView1.ClientID + "', 250, 550 , 22 ,false); </script>", false);


Script
 function MakeStaticHeader(gridId, height, width, headerHeight, isFooter) {
        var tbl = document.getElementById(gridId);
        if (tbl) {
            var DivHR = document.getElementById('DivHeaderRow');
            var DivMC = document.getElementById('DivMainContent');
            var DivFR = document.getElementById('DivFooterRow');
.........

Structure for a Grid

 <%-- root --%>
    <div style="text-align:left;" id="DivRoot">
        <div style="overflow: hidden;" id="DivHeaderRow">
       </div>

        <%-- scroll --%>
        <div style="overflow:scroll;" onscroll="OnScrollDiv(this)" id="DivMainContent">

          <asp:GridView ID="GridView2" runat="server" Width="100%" BorderWidth="1px" AutoGenerateColumns="False" BackColor="gray" ForeColor="white" ShowFooter="false">
             <Columns>
                 ..........
             </Columns> 
          </asp:GridView>        
        </div>

       <%-- footer --%>
       <div id="DivFooterRow" style="overflow:hidden">
       </div>
    </div>


for Other Grid on the same page DivRoot, DivMainContent, DivFooterRow are already declared

 <%-- root --%>
    <div style="text-align:left;" id="DivRoot">
        <div style="overflow: hidden;" id="DivHeaderRow">
       </div>

        <%-- scroll --%>
        <div style="overflow:scroll;" onscroll="OnScrollDiv(this)" id="DivMainContent">

          <asp:GridView ID="GridView1" runat="server" Width="100%" BorderWidth="1px" AutoGenerateColumns="False" BackColor="gray" ForeColor="white" ShowFooter="false">
             <Columns>
                 ..........
             </Columns> 
          </asp:GridView>        
        </div>

       <%-- footer --%>
       <div id="DivFooterRow" style="overflow:hidden">
       </div>
    </div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900