Freeze gridview pager while scrolling vertically - asp.net

I have a gridview.
I have to implement both Paging as well as make the page scrollable both horizontally and vertically. The page navigation bar comes at the bottom.
While scrolling the page vertically, I want two things -
The gridview headers should also be frozen.
gridview pagers should also be frozen.
I mean they should not scroll along with the data.
Only the rows should scroll.
I have implemented -
1. Fixed header using CSS
2. Horizontally scrollable using CSS
3. Vertically scrollable using CSS
I am not able to
1. Fix the Pager.
My code:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<style type="text/css">
div#gvResultStyle
{
width: 500px;
height: 350px;
overflow: scroll;
position: relative;
}
div#gvResultStyle th
{
background-color: Navy;
color: White;
top: expression(document.getElementById("gvResultStyle").scrollTop-2);
left: expression(parentNode.scrollLeft);
position: relative;
z-index: 20;
}
.gvPager
{
left: 0px;
width: 400px;
border-right-style: solid;
position: absolute;
height: 10px;
text-align: left;
border-right-color: Navy;
}
</style>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">
www.asp.net</a>.
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
<div id="gvResultStyle">
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="SqlDataSource1" AllowPaging="true" PageSize="20" CssClass="gvResultStyle">
<PagerSettings Position="Bottom" />
<PagerStyle CssClass="gvPager" />
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" />
<asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
<asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" />
<asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" />
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT * FROM [Alphabetical list of products]"></asp:SqlDataSource>
<br />

i wrote jQuery plug-in can fixed header and freeze column, it can be apply to GridView.
see the image:
It also support pager:
Demo: Pager Support

Related

I am trying to add bootstrap active class to the asp.net gridview row

I am trying to add active class to the GridView. Once I select a row in the Grid I want to make it as selected using Bootstrap.It might be asked by folks before. But I couldn't find out this.
GridView:
<div class="row">
<asp:UpdatePanel ID="UpdatePanelGrid" runat="server">
<ContentTemplate>
<div class="history-table ">
<asp:GridView CssClass="col-lg-6 col-md-8 col-sm-10 col-xs-12" DataKeyNames="HistoryId" ID="gvFunds" runat="server"
AutoGenerateColumns="False" OnSelectedIndexChanged="gvFunds_SelectedIndexChanged" OnRowDataBound="gvFunds_RowDataBound">
<Columns>
<asp:BoundField DataField="HistoryId" Visible="false" />
<asp:BoundField DataField="Date" HeaderText="Date" ReadOnly="True" />
<asp:BoundField DataField="Time" HeaderText="Time" ReadOnly="True" />
<asp:BoundField DataField="UserId" HeaderText="User ID" ReadOnly="True" />
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
CSS:
.history-table table {
text-align: center;
border: none;
}
.history-table table tr:nth-child(2n+1) {
background-color: #C6C0AA;
}
.history-table table tr th {
text-align: center;
height: 35px;
border: none;
background-color: #C6C0AA;
}
.history-table table td {
height: 25px;
border: none;
}
.history-table table tr:hover {
background-color: #8A2A2A;
color: #FFF;
cursor: pointer;
}
.history-table table tr:first-child:hover {
color: #000;
}
After trying a lot of ways finally I got the answer. I can do it easily using GridView attributes. I am sharing here for your reference.
<div class="row" style="margin: 0px;">
<asp:UpdatePanel ID="UpdatePanelGrid" runat="server">
<ContentTemplate>
<div class="gridview-table ">
<asp:GridView CssClass="col-xs-12 gridview-with-default-selected-row" DataKeyNames="HistoryId" ID="gvFunds" ClientIDMode="Static" runat="server" ViewStateMode = "Enabled"
AutoGenerateColumns="False" OnSelectedIndexChanged="gvFunds_SelectedIndexChanged" OnRowDataBound="gvFunds_RowDataBound">
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<SelectedRowStyle Font-Bold="True" BackColor="#8a2a2a" ForeColor="White"></SelectedRowStyle>
<AlternatingRowStyle BackColor="White" ForeColor="Black" />
<RowStyle BackColor="#CDC7B1" BorderStyle="None" Height="30px" ></RowStyle>
<HeaderStyle Height="30px" BackColor="#F5F4EF" BorderColor="#F5F4EF" Font-Names="vegurregular" Font-Size="12px" Font-Bold="False"></HeaderStyle>
<Columns>
<asp:BoundField DataField="HistoryId" HeaderText="History ID" />
<asp:BoundField DataField="Date" HeaderText="Date" ReadOnly="True" />
<asp:BoundField DataField="Time" HeaderText="Time" ReadOnly="True" />
<asp:BoundField DataField="UserId" HeaderText="User ID" ReadOnly="True" />
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>

How to make gridview scrollable horizantally and vertically?

I have a gridview inside a div as follows:
<div id="divPopUpFiles" runat="server" style="background-color: White; width: 800px;
height: 410px; position: absolute; border-color: Black; border-style: groove;
border-width: thin; display: none; z-index: 10001;">
<asp:UpdatePanel ID="PopUpPanel" runat="server" Visible="false" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:PostBackTrigger ControlID="btnOk"/>
</Triggers>
<ContentTemplate>
<asp:Label ID="lblModifiedFilesMessage" runat="server" />
<asp:GridView ID="gvPopUpModifiedFiles" runat="server" AutoGenerateColumns="False"
CssClass="dataTable" ShowHeaderWhenEmpty="True" style="overflow: auto; width: 800px; max-height: 200px;">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkFileSelect" runat="server" Checked="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="FileName" DataField="FileName" />
</Columns>
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
</asp:GridView>
<asp:Button ID="btnOk" Text="OK" runat="server" Font-Bold="true" onclick="btnOk_Click" /><br />
</ContentTemplate>
</asp:UpdatePanel>
</div>
I used the overflow:auto still I am unable to make my grid scrollable
use this code.
<div style="overflow: auto; width: 800px; max-height: 200px;">
<asp:GridView ID="gvPopUpModifiedFiles" runat="server" AutoGenerateColumns="False"
CssClass="dataTable" ShowHeaderWhenEmpty="True" style="overflow: auto; width: 800px; max-height: 200px;">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkFileSelect" runat="server" Checked="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="FileName" DataField="FileName" />
</Columns>
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
</asp:GridView>
</div>

Display pop-up with simple text upon Button click

I have a button placed on each row of my GridView. When the user presses the button I would like to display a simple popup where I show text. Part of the text is the DataKeyName related to the specific row.
I already tried with ModalPopupExtender myMPE triggered by the button and I used a Panel myPanel as PopupControlID. The problem is that the TextBox txtPanel of the Panel where I place the DataKeyName value is always empty. I tried to debug without myMPE and the txtPanel of the Panel is correctly filled. I guess it makes a mess with the postbacks.
Anybody knows a solution?
Are you doing a manual refresh of the UpdaePanel on the modal popup panel ? If not, try manually refreshing the updatePanel & set its updateMode to Conditional.
Check above example
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="Stylesheet" type="text/css" href="css/StyleSheet.css" />
<style type="text/css">
.modal
{
background-color: Aqua;
width: 150px;
height: 100px;
padding: 6px;
}
.modalBackground
{
background-color: #CCCCFF;
filter: alpha(opacity=40);
opacity: 0.5;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:UpdatePanel ID="upnGrid" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView CssClass=".Grid-blue" ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="LinqDataSource1">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" />
<asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
<asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" />
<asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" OnClick="lbEdit_Click">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext"
EntityTypeName="" TableName="Products">
</asp:LinqDataSource>
</div>
<ajaxToolkit:ModalPopupExtender BackgroundCssClass="modalBackground" ID="mpeDetails"
CancelControlID="btnClosePopup" TargetControlID="btnShowModal" PopupControlID="pnlDetails"
runat="server">
</ajaxToolkit:ModalPopupExtender>
<asp:Button ID="btnShowModal" runat="server" Text="Button" Style="display: none" />
<asp:Panel ID="pnlDetails" CssClass="modal" runat="server" Style="display: none">
<asp:UpdatePanel ID="upnDetails" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<label>
ID:</label><asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<br />
<label>
Name:</label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
</ContentTemplate>
</asp:UpdatePanel>
<div>
<asp:Button ID="btnClosePopup" runat="server" Text="Cancel" /></div>
</asp:Panel>
</form>
</body>
</html>
.CS
protected void lbEdit_Click(object sender, EventArgs e)
{
LinkButton lbTemp = (LinkButton)sender;
if (lbTemp != null)
{
GridViewRow grow =(GridViewRow) lbTemp.NamingContainer;
int id = Convert.ToInt32(GridView1.DataKeys[grow.RowIndex][0].ToString());
mpeDetails.Show();
txtID.Text = id.ToString();
upnDetails.Update();
}
}

How to shrink size of DataGrid?

I am developing a VB.NET app which returns data to a DataGrid. Everything works correctly now except for one thing. I want all of the blank white space below my datagrid to not appear, so that users don't have to worry about scrolling down the page.
Currently, it shows the DataGrid correctly, with a scrollbar and this grid takes up about half the height of my monitor. But then there is alot of empty white space below this grid. How can I remove that?
Here is the end of my ASPX file:
<head>
<title></title>
<style type="text/css">
.DataGridFixedHeader {background-color: #336699; color:White; font-weight: "bold"; position:relative; top:expression(this.offsetParent.scrollTop);}
#txtFind{ width:150; padding:5px; outline:none; height:20px; }
.focusField{ border:solid 2px #73A6FF; background:#EFF5FF; color:#000; }
.idleField{ background:#EEE; color: #6F6F6F; border: solid 2px #DFDFDF; }
</style>
</head>
<body>
<form runat="Server" defaultbutton= "btnFind" method="post" id="Form1">
<div style="font-size:18pt; font-family:verdana; font-weight:bold; color:#336699">
Parts Watch List
</div>
<hr style="font-weight: bold; font-size: 20pt; color:#000080;" />
<div style="height: 380px; text-align: center; position: static;">
<input id="part_transfer" type="hidden" runat="server"/>
<input id="part_desc_transfer" type="hidden" runat="server"/>
<asp:Panel id="Panel1" runat="server" HorizontalAlign = "Center">
<span style="font-weight: bold; text-align: left; font-size: 15pt;">
Calculation:</span><br />
Reliability Rate = 1 - ( number of failed parts in the last 6 months / Part Multiplier * Average instrument Census in the last 6 months),<br />
Where
<br />
Number of failed parts - Summation of failures of a part for a 6 month period<br />
Part Multiplier - Number that represents how many times a part is used on the intrument<br />
Average instrument census - Average of the instrument census for the same
6 month timeframe as failed parts<br />
<br />
Please choose one of the parts below to view the control charts.</p>
</asp:Panel>
<asp:Panel id="Panel2" runat="server" Visible="false">
<chart:WebChartViewer id="WebChartViewer1" runat="server" HorizontalAlign="Center" />
</asp:Panel>
</div>
<hr style="width: 90%; position: static;" />
<div style="text-align: center; position: static; ">
<asp:Label id="CensusLastUpdate" runat="server"/><br />
<asp:Button id="btnExport" runat="server" Text="Export to Excel"></asp:Button>
<asp:CheckBox id="check1" Text="Display Only Parts Below Threshold" TextAlign="Right" AutoPostBack="True" OnCheckedChanged="ReRun_Main" runat="server" />
<br />
<asp:TextBox ID="txtFind" Text="Enter Part Number" runat="server" />
<asp:Button ID="btnFind" Text="Search" runat="server" OnClick="SearchTable" />
</div>
<% Dim scrollPosURL As String = "../includes/ScrollPos.htc"%>
<input id="saveScrollPos" type="hidden" runat="server" name="saveScrollPos"/>
<table border="0" cellspacing="0" align="center" style="" >
<tr>
<td>
<div style="OVERFLOW: auto; HEIGHT: 400px; vertical-align: top; ">
<ASP:DATAGRID ID="dgTable" HorizontalAlign="Center" runat="server" AutoGenerateColumns="False" ShowHeader="True" OnItemDataBound="DataGrid1_ItemDataBound">
<AlternatingItemStyle BackColor = "#eeeeee" />
<HEADERSTYLE CssClass="ms-formlabel DataGridFixedHeader" />
<COLUMNS>
<ASP:BOUNDCOLUMN HEADERTEXT="PN" DATAFIELD="PART_NUM" READONLY="true" ItemStyle-Width="130px" ItemStyle-Font-Size="8"/>
<ASP:BOUNDCOLUMN HEADERTEXT="PART_DESC" DATAFIELD="PART_DESC" READONLY="true" ItemStyle-Width="150px" ItemStyle-Font-Size="8"/>
<ASP:BOUNDCOLUMN HEADERTEXT="numFailed" DATAFIELD="NUM_FAILED" READONLY="true" ItemStyle-Width="150px" ItemStyle-Font-Size="8"/>
<ASP:BOUNDCOLUMN HEADERTEXT="AvgCensus" DATAFIELD="AVG_CENSUS" READONLY="true" ItemStyle-Width="150px" ItemStyle-Font-Size="8"/>
<ASP:BOUNDCOLUMN HEADERTEXT="PartMultiplier" DATAFIELD="PartMultiplier" READONLY="true" ItemStyle-Width="150px" ItemStyle-Font-Size="8"/>
<ASP:BOUNDCOLUMN HEADERTEXT="ReliabilityRate" DATAFIELD="RELIABILITY_RATE" READONLY="true" ItemStyle-Width="105px" ItemStyle-Font-Size="8"/>
<ASP:BOUNDCOLUMN HEADERTEXT="PRIORITY" DATAFIELD="PRIORITY" READONLY="true" Visible="False" ItemStyle-Width="0px" ItemStyle-Font-Size="8"/>
<ASP:BOUNDCOLUMN HEADERTEXT="Criticality" DATAFIELD="Criticality" READONLY="true" ItemStyle-Width="105px" ItemStyle-Font-Size="8"/>
</COLUMNS>
</ASP:DATAGRID>
</div>
</td>
</tr>
</table>
</form>
<!-- Javascript at the bottom for fast page loading -->
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.js" type="text/javascript"></script>
<script type="text/javascript"> window.jQuery || document.write('<script src="js/libs/jquery-1.6.1.js">\x3C/script>')</script>
<!-- Scripts concatenated -->
<script src="js/plugins.js" type="text/javascript"></script>
<script src="js/script.js" type="text/javascript"></script>
<!-- End scripts -->
</body>
</html>
Reduce the style height (currently set to 400px) on the DIV that it lives in.

How To Prevent TreeView from changing its position?

Whenever I collapse or open node in the tree view, it jumps up and down to be in the middle of the page. Is there any way to keep it still in its position and prevent that?
Here's some CSS to fix this (I'm assuming this is happening in Firefox?):
<div id="idTreeView">
<asp:TreeView ID="TreeView1" runat="server"
DataSourceID="SiteMapDataSource1"
HoverNodeStyle-Height="0" Font-Bold="true" ImageSet="BulletedList">
<RootNodeStyle Font-Bold="True" />
<ParentNodeStyle VerticalPadding="0px" Font-Bold="True" Font-Underline="false" />
<HoverNodeStyle Font-Underline="false" ForeColor="#5555DD" />
<NodeStyle Font-Bold="False" Font-Size="8pt" CssClass="sitelink"
ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</div>
div#idTreeView img
{
display: block;
float: left;
}
div#idTreeView div
{
display: inline-block;
}
div#idTreeView .sitelink a
{
text-decoration:none;
}

Resources