Saturday, April 28, 2012

Bind Table using javascript like grid or repeater.



Bind Any Table which comes from code behind stored procedure calling....Like this simply make a method which is webmethod into code behind and call it on client side.The Total code is below I am writing here.
//--------------------Bind Elective Papers on Change Of Specialization------------------
        function ShowElectivePapers() {

            var dCID = document.getElementById('<%= ddlCourse.ClientID%>');
            var CourseID = dCID.options[dCID.selectedIndex].value;
            var dSID = document.getElementById('<%= ddlSemester.ClientID%>');
            var SemID = dSID.options[dSID.selectedIndex].value;
            var dSpec = document.getElementById('<%= ddlSpecialization.ClientID%>');
            var SpecID = dSpec.options[dSpec.selectedIndex].value;
            if (SpecID != 0) {
                BindElectivePapers(CourseID, SemID, SpecID);
            }
        }


        function BindElectivePapers(CCode, SemId, Spec) {

            $.ajax({
                type: "POST",
                url: "StudentRegistration.aspx/BindElectivePapers",
                contentType: "application/json; charset=utf-8",
                data: "{'CCode': '" + CCode + "','SemId': '" + SemId + "','Spec': '" + Spec + "'}",
                dataType: "json",
                async: false,
                success: AjaxSucceeded,
                error: AjaxFailed
            });

            function AjaxSucceeded(result) {
                DisplayChildren(result);
            }
            function AjaxFailed(result) {
                alert('no success');
            }
            function DisplayChildren(result) {
                var dtEpaper = eval(result.d);
                if (dtEpaper != null && typeof (dtEpaper) == "object") {
                    document.getElementById('<%= dvElectivePapers.ClientID%>').style.display = '';
                    var s = new Array();
                    s[s.length] = "
Elective Papers
"
                    s[s.length] = "
"
                    s[s.length] = "
"
                    s[s.length] = "
";
                    s[s.length] = "
";
                    s[s.length] = "
";
                    s[s.length] = "
";
                    s[s.length] = "
";
                    for (var i = 0; i < dtEpaper.Table.length; i++) {
                        s[s.length] = "
";
                        s[s.length] = "
";
                        s[s.length] = "
";
                        s[s.length] = "
";
                    }
                    s[s.length] = "
Paper CodePaper Name
" + dtEpaper.Table[i].Code + "" + dtEpaper.Table[i].SubName + "
";
                    s[s.length] = "
";
                    document.getElementById("<%= dvElectivePapers.ClientID%>").innerHTML = s.join("");
                }
                else {
                    document.getElementById('<%= dvElectivePapers.ClientID%>').style.display = 'none';
                }
            }
        }

        // -----------------------.cs Code with stored procedure caliing--------------

 #region "BindElectivePapers"
    [WebMethod]
    public static Dictionary BindElectivePapers(string CCode, string SemId, string Spec)
    {
        CommonManger Obj = new CommonManger();
        DataTable objEPaper = new DataTable();
        objEPaper = Obj.GetTableWithParameter("SP_GetElectivePapers_ViaSpecialization", "@CrsID", CCode, "@Sem", SemId, "@CrsSpl", Spec);
        if (objEPaper.Rows.Count > 0)
        {
            return JsonMethods.ToJson(objEPaper);
        }
        else
        {
            return null;
        }
    }
    #endregion

Wednesday, April 25, 2012

Make custom order in sql



Hi,
I can also make my query according to my customization order called Custom Order .It works as i want in which order my out will show .As simple as it is...
SELECT COUNT(*)StudentCount,SessionCode FROM dbo.tblStudentNEDESROLL GROUP BY SessionCode ORDER BY CASE
            WHEN SessionCode = '0110' THEN 1
            WHEN SessionCode = '0710' THEN 2
            WHEN SessionCode = '0111' THEN 3
            WHEN SessionCode = '0711' THEN 4
            WHEN SessionCode = '0112' THEN 5
           
         END

Friday, April 20, 2012

Set Default database in sql on New Query


This is to set any database when U want any database come to add query.In ur sql.
Exec sp_defaultdb @loginame='login', @defdb='master'