jump to navigation

Freeze a Gridview header in ASP.NET 3.5 January 27, 2009

Posted by Sabs in Technology.

My current project had a typical requirement. Our custom gridview control sometimes has 100’s of record in it.  Obviously we want to implement a freezed header kind of functionality to provide ease in viewing of large number of record in gridview. My gridview has also got dynamic columns as per the user rights hence i really can’t implement the panel kind of feature with scrollbars. That is a very good option for a fixed column gridview type of feature. After googling for few hours i came upon a solution and after doing some minor tweaks the solution worked for me and bingo !!

Here’s the sample code

Make sure that your gridview is enclosed within a div tag with a overflow-y: scroll;overflow-x: hidden style specified on it. Also specify the height of that div as per the height of your required fixed header. Also place a empty div tag  on top of the above mentioned div tag which will be used for the scroll functionality. Just like in sample below –

<!–an extra div required for scroll functionality –>
<div id=”divScroll” runat=”server”>
<div id=”divContainer” style=”overflow-y: scroll;overflow-x: hidden; height: 200px;” runat=”server”>
<tts:GridViewEx ID=”gvPackingList” runat=”server” AutoGenerateColumns=”False” AllowSorting=”true”
CssClass=”tblGrid” DataKeyNames=”PackingListItemId” EnableViewState=”True” PageSize=”100″
ShowSortIndicators=”false” OnRowDataBound=”gvPackingList_RowDataBound”
AllowPaging=”true” OnPageIndexChanging=”gvPackingList_PageIndexChanging”
OnRowCommand=”gvPackingList_RowCommand” OnSorting=”gvPackingList_Sorting”>
<AlternatingRowStyle CssClass=”alt_row” />
<asp:TemplateField HeaderText=”Action”>
<asp:ImageButton ID=”lnkEdit” runat=”server” Text=”Edit” ImageUrl=”~/img/icons/page_edit.png”
ToolTip=”Edit Packing Item” CommandName=”Edt” CommandArgument='<%# Bind(“PackingListItemId”) %>’
<asp:ImageButton ID=”lnkDel” runat=”server” Text=”Delete” ImageUrl=”~/img/icons/ico_delete.png”
ToolTip=”Delete Packing Item” CommandName=”Del” CommandArgument='<%# Bind(“PackingListItemId”) %>’
OnClientClick=”return confirmPackingItemDelete();” />
<tts:SelectionField DataField=”PackingListItemId”>
<HeaderStyle />

Now call this javascript code on your page load –

function FreezeGridViewHeader() {
/// <summary>
///   Used to create a fixed GridView header and allow scrolling
/// </summary>
var grid = document.getElementById(‘<%= gvPackingList.ClientID %>’);
var gridclone = grid.cloneNode(true);

for (i = gridclone.rows.length – 1; i > 0; i–)



var div = document.getElementById(‘<%= divScroll.ClientID %>’);
if (navigator.appName != “Microsoft Internet Explorer”) {
//need to manage div width in case of mozilla
div.style.width = ‘883px’;

Here gvPackingList.ClientID is the gridview on which we want scroll to appear with fixed header. I have to specify a width for mozilla ff since as per my UI and css the gridview was giving some issues. That part of code can be completely optional for you.

Now try it and let me know of any loopholes !!

Using C++ DLL in ASP.NET (C#) February 27, 2008

Posted by Sabs in Technology.

In my places in our program we have to use DLLImport, but it only works if the DLL is loaded. In windows application you can simply overcome this by placing the DLL in a designated folder, but in case of an ASP.NET application the code is compiled in an location which can’t be determined previously. It’s usually accessed from system32 ASP.NET folder and from a file created dynamically having some random naming. In .NET 1.1 the dynamic loading of dll using relflection was an available option, which we can also follow in ASP.NET 2.0 (see here) but we now also have another. We can load the DLL by calling Loadlibrary and then dll will be available to us in the memory and we can use it as we want.

Declaration of LoadLibrary in C#

static extern IntPtr LoadLibrary(string lpFileName);

public static extern IntPtr FreeLibrary(IntPtr library);
// This is a sample Dll, whose function Function1 is required for us in the application.

[DllImport(“Sample.dll”, EntryPoint = “Function1”)]
public static extern void Function1(Byte[] inStr, Byte[] outStr, long in_Len);

The use of LoadLibrary in C#

// The physical path of the DLL

string DLLPath = HttpContext.Current.Request.PhysicalApplicationPath + “\References\Sample.dll”;
//Call LoadLibrary
IntPtr lib = LoadLibrary(DLLPath); // If the lib is zero, the code has failed

// Use the declared function, if required or any other stuff
pwd, Password.Text.Length*2);
Don’t forget to free it

FreeLibrary(lib); // Check HRESULT, if that bothers you

Please do send me any enhancements, updates or suggestions regarding the above mentioned post.

Nasty Pop-up November 12, 2007

Posted by Sabs in Technology.
add a comment

Nasty Popup

Does anyone knows how to get rid of this nasty pop-up that comes up usually when we are browsing some secured sites. I am getting it while browsing a secured site using AxSHDocVw. AxWebBrowser control in dotnet. I am programatically trying to visit a site without showing a UI to the user and obviously this pop-up also needs to be handled through my code. Any suggestions, most welcome….

Microsoft surface June 22, 2007

Posted by Sabs in Technology.

As stated by Wikipedia, Microsoft Surface (Codename: Milan), is a forthcoming product from Microsoft which is developed as a software and hardware combination technology that allows a user, or multiple users, to manipulate digital content by the use of natural motions, hand gestures, or physical objects. It was announced on May 30, 2007 at D5, and is expected to be released by commercial partners in November 2007. Initial customers will be in the hospitality businesses, such as restaurants, hotels, retail, and public entertainment venues.

Surface is essentially a Windows Vista PC tucked inside a black table base, topped with a 30-inch touchscreen in a clear acrylic frame. Five cameras that can sense nearby objects are mounted beneath the screen. Users can interact with the machine by touching or dragging their fingertips and objects such as paintbrushes across the screen, or by setting real-world items tagged with special barcode labels on top of it.

Surface has been optimized to respond to 52 touches at a time. During a demonstration with a reporter, Mark Bolger, the Surface Computing group’s marketing director, “dipped” his finger in an on-screen paint palette, then dragged it across the screen to draw a smiley face. Then he used all 10 fingers at once to give the face a full head of hair.

In addition to recognizing finger movements, Microsoft Surface can also identify physical objects. Microsoft says that when a diner sets down a wine glass, for example, the table can automatically offer additional wine choices tailored to the dinner being eaten.

Rather a great achievement, but it seems soon these things will outclass programming, as coding will become as simpler as making a face on sand by a finger, there where we programmers will go !!