jump to navigation

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

Posted by Sabs in Technology.
3 comments

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>
<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” />
<Columns>
<asp:TemplateField HeaderText=”Action”>
<ItemTemplate>
<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();” />
</ItemTemplate>
<HeaderStyle/>
</asp:TemplateField>
<tts:SelectionField DataField=”PackingListItemId”>
<HeaderStyle />
</tts:SelectionField>
</Columns>
</tts:GridViewEx>
</div>

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–)

{

gridclone.deleteRow(i);
}

grid.deleteRow(0);
var div = document.getElementById(‘<%= divScroll.ClientID %>’);
div.appendChild(gridclone);
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 !!

Marriages and democracy September 12, 2008

Posted by Sabs in Copied.
add a comment
An interesting article by Ramesh Ramanathan who is co-founder of Janaagraha. Möbius Strip, much like its mathematical origins, blurs boundaries. It is about the continuum between the state, market and our society.
My parents celebrated their 50th wedding anniversary a few months ago.
They have a good marriage in many ways, but importantly, a balanced one. Balanced in the sense that my mother gets her way on many family issues. But it wasn’t like this when she got married. Theirs was an arranged marriage, in the classic Indian tradition, where the elders (read fathers) decide on one’s choice of life partner. When the news of the arrangement reached her, she had only two requests — not demands — of her father.

We Indians hold different views on public versus personal choices: political rights versus choice of a life partner
“The first”, she told me, with her usual smiling eyes, “was that I could finish my studies in music.” She was in her final year degree at Stella Maris in Madras, and was passionate about the subject.
“The second was that I didn’t want to pierce my nose!” she laughed at the seeming silliness of the request. But she was only 18 at the time.
She didn’t get either of her requests, unfortunately.
The practice of arranged marriages is common even today in India, where parents and elders decide the life partners for their children. Of course, many Indian families have moved to a form of “facilitated arranged marriage”, where the elders initiate the meetings, and then leave the actual decision to the potential partners. However, there still are hundreds of thousands of extreme arranged marriages, or “forced arranged marriages” in India, in which there is no choice available to the individuals concerned, often the woman.
I’m not going to dwell on the relative merits of these different forms of marriage. I want to focus instead on the extreme arranged marriage form where there is little or no choice, and look at it in a different context. What does this practice say about us as a democracy?
Given the nature of the term, there is no single definition for democracy. But the oracle of collective wisdom — Wikipedia — says, “‘Democracy’ is a form of government in which the supreme power is held completely by the people under a free electoral system.”
The stuff we learn in our civics books. But importantly, it goes on to state that there are “two principles that any definition of democracy include. The first principle is that all members of the society have equal access to power and the second that all members enjoy universally recognized freedoms and liberties.” Essentially, that each individual has the right to voice their minds on issues.
So, at the heart of the idea of democracy is the freedom to make choices. But when we talk of democracy and choices, we tend to confine these to “public” issues: should India sign the nuclear treaty, what should be the resolution in Singur, should we have reservations in our IITs? We hold different views on these issues. But we all agree that we have the right to express our view, and engage in constructive debate.
This is at the heart of democracy.
Over the past 60 years, Indians have shown that we are passionate about protecting these rights. Time and again we have shown that we cherish this concept called democracy and that we wouldn’t have it any other way, even if it means slowing our progress as a nation in material or economic terms.
So, how come we are so passionate about protecting our political rights — wanting to have a choice to make decisions about our roads and schools and hospitals — but so completely comfortable with giving up choice in the single biggest decision that impacts our lives — that of a life partner?
How come we hold different views on public versus personal choices?
Among the hundreds of blogs on arranged marriages, I found this interesting point made by a blogger called Shef:
“Arranged marriages can work and they can also fail. Love marriages can work and they can also fail. The point (is) the higher principle: Should people have a choice about who they marry? It’s a bit like democracy vs dictatorship — arranged marriages smack of ‘We know what’s best for you’. Sure, the results can be OK sometimes. But do those good days justify the system?” (To see the full thread, go to http://www.zackvision.com/weblog/2003/06/arranged-marriage.html)
There are clearly conflicts in the positions between arranged marriages and democratic choice. So, are we a schizophrenic society, in the sense that we live in compartmentalized worlds, comfortable with the contradictions in these positions?
Or, alternatively, should we see our grand adventure with democracy in a completely different light?
As a kind of escapist therapy to relieve the oppression that so many of us face in our daily lives. Maybe we see elections not as an expression of choice, but as periodic national healing sessions — the polling booth as counselling centre.

Beautiful Story… May 1, 2008

Posted by Sabs in Copied.
add a comment

Supposedly a true story from “somebody”….. Here it goes….

My wife called, ‘How long will you be poring over that newspaper? Will you come here and make your darling daughter eat her food?’

I tossed the paper away and rushed to the scene.My only daughter Sindu looked frightened.

Tears were welling up in her eyes. In front of her was a bowl filled to its brim with Curd Rice.
Sindu is a nice child, quite intelligent for her age. She has just turned eight.
She particularly detested Curd Rice. My mother and my wife are orthodox, and believe firmly in the ‘coolingeffects’ of Curd Rice! I cleared my
throat, and picked up the bowl. ‘Sindu, darling, why don’t you take a few mouthful of this Curd Rice?Just for Dad’s sake, dear. And, if you don’t,
your Mom will shout at me’I could sense my wife’s scowl behind my back.

Sindu softened a bit, and wiped her tears with the back of her hands.
‘OK, Dad. I will eat – not just a few mouthfuls, but the whole lotof this.
But, you should…’ Sindu hesitated.
‘Dad, if I eat this entire curd Rice, will you give me whatever I ask for?’

‘Oh sure, darling’.

‘Promise?’

‘Promise’.

I covered the pink soft hand extended by my daughter with mine, and clinched the deal. ‘Ask Mom also to give a similar promise’, my daughter
insisted. My wife slapped her hand on Sindu’s, muttering ‘Promise’, without any emotion.

Now I became a bit anxious. ‘Sindu dear, you shouldn’t insist on getting a computer or any such expensive items. Dad does not have that kind of money
right now. OK?’

‘No, Dad. I do not want anything expensive’. Slowly and painfully, she finished eating the whole quantity.
I was silently angry with my wife and my mother for forcing my child eat something that she detested.
After the ordeal was through, Sindu came to me with her eyes wide with expectation.
All our attention was on her.

‘Dad, I want to have my head shaved off, this Sunday!’ was her demand.

‘Atrocious!’ shouted my wife, ‘A girl child having her head shaved off?
Impossible!’

‘Never in our family!’ my mother rasped.
‘She has been watching too much of television. Our culture is getting totally spoiled with these TV programs!’

‘Sindu darling, why don’t you ask for something else? We will be sad seeing you with a clean-shaven head.’

‘No, Dad. I do not want anything else’, Sindu said with finality.

‘Please, Sindu, why don’t you try to understand our feelings?’ I tried to plead with her.

‘Dad, you saw how difficult it was for me to eat that Curd Rice’. Sindu was in tears.

‘And you promised to grant me whatever I ask for. Now, you are going back on your words. Was it not you who told me the story of King Harishchandra,
and its moral that we should honor our promises no matter what?’

It was time for me to call the shots. ‘Our promise must be kept.’

‘Are you out your mind?’ chorused my mother and wife.

‘No. If we go back on our promises, she will never learn to honor her own. Sindu, your wish will be fulfilled.’

with her head clean-shaven, Sindu had a round-face, and her eyes looked big and beautiful.

On Monday morning, I dropped her at her school.
It was a sight to watch my hairless Sindu walking towards her classroom.
She turned around and waved.

I waved back with a smile.
Just then, a boy alighted from a car, and shouted, ‘Sinduja, please wait for me!’

What struck me was the hairless head of that boy.
‘May be, that is the in-stuff’, I thought.

‘Sir, your daughter Sinduja is great indeed!’
Without introducing herself, a lady got out of the car, and continued,’

That boy who is walking along with your daughter is my son Harish. he is suffering from… … leukemia.’ She paused to muffle her sobs.

‘Harish could not attend the school for the whole of the last month. He lost all his hair due to the side effects of the chemotherapy. He refused
to come back to school fearing the unintentional but cruel teasing of the schoolmates.’

Sinduja visited him last week, and promised him that she will take care of the teasing issue.But, I never imagined she would sacrifice her lovely hair
for the sake of my son! Sir, you and your wife are blessed to have such a noble soul as your daughter.’

I stood transfixed. And then, I wept.
‘My little Angel, you are teaching me how self-less real love is!’

*The happiest people on this planet are not those who live on their own terms but are those who change their terms for the ones whom they love..*

Love and Marriage April 30, 2008

Posted by Sabs in Copied.
add a comment

The child was a typical four-year-old girl – cute,
inquisitive, bright as a new penny.

When she expressed difficulty in grasping the concept
of marriage, her father decided to pull out his wedding
photo album, thinking visual images would help.

One page after another, he pointed out the bride
arriving at the church, the entrance, the wedding
ceremony, the recessional, the reception, etc.

“Now do you understand?” he asked.

“I think so,” she said, “is that when mommy came to
work for us?

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

Posted by Sabs in Technology.
14 comments

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#

[DllImport(“kernel32.dll”)]
static extern IntPtr LoadLibrary(string lpFileName);

[DllImport(“kernel32.dll”)]
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
Function1(System.Text.ASCIIEncoding.Unicode.GetBytes(Password.Text),
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.

Thinking Cinema January 14, 2008

Posted by Sabs in Multifarious.
1 comment so far

Aamir and Darsheel in TZP

Few days back, I got a chance to watch the movie “Taare Zameen par”. Simply a masterpiece, everyone will agree. From past few years, I have been noticing a huge change in the content of Indian Cinema. I can still remember, some time before a movie always means a hero, heroine and few songs and their villainous fathers and uncles. After seeing them, I always used to ponder, that is it is the only topic, worth watching available to us? But I am immensely happy after watching the nowadays movies content. Previously a movie like TZP can easily come into the category of so called art cinema and at that time no one can ever dreamt of being associated with a so called art movie. The movies of social interest always use to fall in that category only. I would like to mention few other classy movies like Black, Cheeni Kum, and Chak De etc. whom I always considered as thinking cinema. We need these kinds of movies who can stimulate our thinking cells and helps us in being a thinking and sensitive individual.

 

I think an actor, director or anyone related to media should never forget his social responsibility. I have seen that everyone gets influenced with the movies they seen, because for us they are still the primary source of our entertainment.

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….

21 Things To Remember.. September 20, 2007

Posted by Sabs in Copied.
1 comment so far

1. No one can ruin your day without YOUR permission.

2. Most people will be about as happy, as they decide to be.

3. Others can stop you temporarily, but only you can do it permanently.

4. Whatever you are willing to put up with, is exactly what you will have.

5. Success stops when you do.

6. When your ship comes in…. make sure you are willing to unload it.

7. You will never have it all together.

8. Life is a journey…not a destination. Enjoy the trip!

9. The biggest lie on the planet When I get what I want I will be happy.

10. The best way to escape your problem is to solve it.

11. I’ve learned that ultimately , ‘takers’ lose and ‘givers’ win.

12. Life’s precious moments don’t have value, unless they are shared.

13. If you don’t start, it’s certain you won’t arrive.

14. We often fear the thing we want the most.

15. He or she who laughs……lasts.

16. Yesterday was the deadline for all complaints.

17. Look for opportunities…not guarantees.

18. Life is what’s coming….not what was.

19. Success is getting up one more time.

20. Now is the most interesting time of all.

And Most of all……………

21. When things go wrong…..don’t go with them.

Searching Eyes… August 24, 2007

Posted by Sabs in Multifarious.
add a comment

A policewomen at Kashmir

I picked this photograph from yesterday’s newspaper (Times of India). The picture is that of a veiled kashmir’s police women. The picture grasped my attention instinctively and so here it is, posted on my blog. Do send me your comments, that what you like most about this picture…

Struggles of Life July 20, 2007

Posted by Sabs in Life.
2 comments

Struggle – as per the definition of dictionary.net it is –

To strive, or to make efforts, with a twisting, or with contortions of the body.

To use great efforts; to labor hard; to strive; to contend forcibly; as, to struggle to save one’s life; to struggle with the waves; to struggle with adversity.

To labor in pain or anguish; to be in agony; to labor in any kind of difficulty or distress.

We all have our own definitions of struggle and i am sure we all would have faced it in one form or other. Some will relate struggle to their personal lives and some with professional. But the question is how you behave during the times of struggle or difficulties. I stumble upon this topic, because yesterday i have to console hard to my dear sister, on the struggles she is facing concurrently at her office front. She was crying consistently because she was not liking the work she is doing currently. I know what you are thinking, that she was crying on such a small matter !! Yup, that’s why I am saying everyone has different definitions to the struggles one face and frankly speaking life is nothing without struggles. When we look back at them they infuse a sense of victory in us and of course satisfaction too. Can any other feeling equates to that triumph. Let me explain my point, with the help of this small story…

Life’s Struggles…

A man found a cocoon of a butterfly. One day a small opening appeared; he sat and watched the butterfly for several hours as it struggled to force its body through that little hole. Then it seemed to stop making any progress. It appeared as if it had gotten as far as it could and it could go no farther.

Then the man decided to help the butterfly, so he took a pair of scissors and snipped off the remaining bit of the cocoon. The butterfly then emerged easily. But it had a swollen body and small, shriveled wings.

The man continued to watch the butterfly because he expected that, at any moment, the wings would enlarge and expand to be able to support the body, which would contract in time.

Neither happened! In fact, the butterfly spent the rest of its life crawling around with a swollen body and shriveled wings. It never was able to fly.

What the man in his kindness and haste did not understand was that the restricting cocoon and the struggle required for the butterfly to get through the tiny opening were nature’s way of forcing fluid from the body of the butterfly into its wings so that it would be ready for flight once it achieved its freedom from the cocoon.

Sometimes struggles are exactly what we need in our life. If nature allowed us to go through our life without any obstacles, it would cripple us. We would not be as strong as what we could have been.

==============================================================================================

so my dear sis, take the struggles of life in a positive way, you never know what new trait they will be adding in your personality….