Monday, August 30, 2010

Custom Modal popup

Css : 
.ModalPopupStyle{background-color: #FFFFFF;}
        .modalBackground
        {
            background-color: Black;
            filter: alpha(opacity=70);
            opacity: 0.7;
        }
        .RoundedCornerTop_Left
        {
            background-image: url(newimages/top_left.png);
            width: 10px;
            height: 21px;
            background-repeat: no-repeat;
        }
        .RoundedCornerBottom_Left
        {
            background-image: url(newimages/bottom_left.png);
            width: 10px;
            height: 10px;
            background-repeat: no-repeat;
        }
        .RoundedCornerBottom_Right
        {
            background-image: url(newimages/bottom_right.png);
            width: 21px;
            height: 10px;
            background-repeat: no-repeat;
        }

Javascript:
function ShowModalPopup(div) {
            $("modalbackgroundElement").style.width = "1261px"; $("modalbackgroundElement").style.position = "fixed"; $("modalbackgroundElement").style.left = "0px"; $("modalbackgroundElement").style.top = "0px"; $("modalbackgroundElement").style.zIndex = "10000"; $("modalbackgroundElement").style.width = screen.width + "px"; $("modalbackgroundElement").style.height = screen.height + "px"; var w = (getWindowWidth() - document.getElementById(div).style.width.substring(0, document.getElementById(div).style.width.indexOf("px"))) / 2; var h = (getWindowHeight() - document.getElementById(div).style.height.substring(0, document.getElementById(div).style.height.indexOf("px"))) / 2 + document.body.scrollTop; $(div).style.top = h + "px"; $(div).style.left = w + "px"; $(div).style.display = "block"; $("modalbackgroundElement").style.display = "block"; $("divBack").style.top = $(div).style.top; $("divBack").style.left = $(div).style.left; $("divBack").style.width = $(div).style.width; $("divBack").style.height = $(div).style.height; $("divBack").style.zIndex = "10001"; $("divBack").style.position = "fixed"; $("divBack").style.margin = "10px"; $("divBack").style.display = "none"; poll_div = div; poll_left = w; poll_top = h;
            var myPageY = 0;
            if (document.all) { myPageY = document.documentElement.scrollTop; }
            else { myPageY = window.pageYOffset; }
            poll_h = myPageY;
            h = (getWindowHeight() - document.getElementById(div).style.height.substring(0, document.getElementById(div).style.height.indexOf("px"))) / 2;
            $(div).style.top = (h) + "px";
            return false;
        }
        function $(id) { if (id == "") { return null; } else { return document.getElementById(id); } }

        function getWindowHeight() {
            var windowHeight = 0; if (typeof (window.innerHeight) == 'number') { windowHeight = window.innerHeight; }
            else {
                if (document.documentElement && document.documentElement.clientHeight) { windowHeight = document.documentElement.clientHeight; }
                else { if (document.body && document.body.clientHeight) { windowHeight = document.body.clientHeight; } }
            }
            return windowHeight;
        }
        function getWindowWidth() {
            var windowWidth = 0; if (typeof (window.innerWidth) == 'number') { windowWidth = window.innerWidth; }
            else {
                if (document.documentElement && document.documentElement.clientWidth) { windowWidth = document.documentElement.clientWidth; }
                else { if (document.body && document.body.clientWidth) { windowWidth = document.body.clientWidth; } }
            }
            return windowWidth;
        }

HTML:
<div id="divBack" style="background-color: #000000; position: absolute; z-index: 100001;">
    </div>
    <div id="modalbackgroundElement" class="modalBackground">
    </div>

<div id="divModal" style="display: none; position: fixed; z-index: 100002; width: 275px;
        height: 200px;">
        <table cellpadding="0" cellspacing="0" border="0" width="275">
            <tr valign="bottom">
                <td class="RoundedCornerTop_Left" width="10px" height="21px">
                </td>
                <td style="background-image: url(newimages/space_cut12.png); background-repeat: repeat-x;
                    padding-right: 15px" valign="bottom" width="254" align="right">
                    <span id="required">* </span><span class="require23">Required fields</span>
                </td>
                <td valign="bottom" width="21">
                    <a href="#" style="text-decoration: none" onclick="javascript:return CloseContactForm();">
                        <img src="newimages/close_btn_16.png" alt="close" border="0" style="vertical-align: bottom"
                            width="21" height="21" /></a>
                </td>
            </tr>
            <tr valign="top" style="width: 254">
                <td colspan="3" class="ModalPopupStyle">
                    <uc1:TaskDetail ID="ContactDetails1" runat="server" strValue="2" />
                </td>
            </tr>
            <tr>
                <td class="RoundedCornerBottom_Left">
                </td>
                <td style="width: 254px; background-color: #fff">
                </td>
                <td class="RoundedCornerBottom_Right">
                </td>
            </tr>
        </table>
    </div>

Thursday, August 26, 2010

USING RECURSIVE COMMON TABLE EXPRESSIONS TO REPRESENT TREE STRUCTURES

Problem : 
Suppose if you have table structure which contains reference as same table for parent entry and you want to display data in table structure then below query will be useful.

Table Structure is:-
catid       catname                parentcatid
1             Cat1                     0
2             Cat2                     0
3             Cat3                     0
4             Cat1_sub1            1
5             Cat1_sub2            1
6             Cat1sub_sub         4
7             Cat2_sub1            2
8             Cat3_sub1            3
9             Cat2_subsub         7
10           Cat2_subsub         6

Desired output is:
Parentcatid                   Tree_Structure
0                                  Cat1
1                                  Cat1->Cat1_sub1
4                                  Cat1->Cat1_sub1->Cat1sub_sub
6                                  Cat1->Cat1_sub1->Cat1sub_sub->Cat2_subsub
1                                  Cat1->Cat1_sub2
0                                  Cat2
2                                  Cat2->Cat2_sub1
7                                  Cat2->Cat2_sub1->Cat2_subsub
0                                  Cat3
3                                  Cat3->Cat3_sub1

SQL Query:-

WITH supplytree AS
(SELECT catid, catname, parentcatid, CAST(catname As varchar(1000)) As si_item_fullname
FROM #tempsample
WHERE parentcatid = 0 
UNION ALL
SELECT si.catid,si.catname,
si.parentcatid,
CAST(sp.si_item_fullname + '->' + si.catname As varchar(1000)) As si_item_fullname
FROM #tempsample As si
INNER JOIN supplytree AS sp
ON (si.parentcatid = sp.catid)
)
SELECT parentcatid, si_item_fullname
FROM supplytree
ORDER BY si_item_fullname;

Wednesday, August 25, 2010

In SQL Server, How to combine multiple row result into one row

Suppose You have below data
Subjectid   Name
1               XYZ
1               ABC
1               PQR
2               RPA
2               PBA
3               TGB

Expected Result :
Subjectid  Name
1              XYZ, ABC, PQR
2              RPA, PBA
3              TGB


SQL Query:
Select Main.SubjectID,
Left(Main.Students,Len(Main.Students)-1) As "Students"
From(Select distinct ST2.SubjectID,
(Select ST1.Name + ',' AS [text()]
From dbo.Students ST1
Where ST1.SubjectID = ST2.SubjectID
ORDER BY ST1.SubjectID
For XML PATH ('')) [Students]
From dbo.Students ST2) [Main]

Tuesday, August 17, 2010

System.Runtime.Serialization.Json namespace is missing

You need to add reference of below dlls

System.Runtime.Serialization.dll
System.ServiceModel.dll
System.ServiceModel.Web.dll

Monday, August 16, 2010

Sharepoint - Apply Forms Authentication

http://technet.microsoft.com/hi-in/windowsserver/sharepoint/dd355701(en-us).aspx
http://www.simple-talk.com/dotnet/windows-forms/configuring-forms-authentication-in-sharepoint-2007/

Twitter Integration with asp.net

http://www.stardeveloper.com/articles/display.html?article=2009061701&page=1