Sunday, July 24, 2011

hello world with jqgrid in asp.net

Hey flock,
I know its been a really a huge time I blogged on something so here I do some research with using JQGRID a plugin for Jquery also Here I would like to show you how to integrate and use it with asp.net.
This may be really funny why I have posted a blog and wasted a time.. If you really see into it. You won't find a good document for using this Jqgrid along with asp.net webforms. Let me begin what are the files I included.
step 1 http://json.codeplex.com/ this is whr we can format json into the c# file. jst include the .dll file into the new visual studio project.

Step 2 Now yo got to add some cs file so that it will be easy for yo to work on.

first : Person.cs --> here yo got to create a property of three variable which you are going to use


using System;
using System.Collections.Generic;
using System.Web;


///

/// Summary description for Person
///

public class Person
{
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}


second: Json.cs where yo will include the values for these properties..

using System.Collections.Generic;


public class Json
{
    public static string ToJson(object obj)
    {
        return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
    }


    public static List GetPersons()
    {
        List persons = new List();
        persons.Add(new Person() { ID = 1, FirstName = "Santhosh", LastName = "Kumar" });
        persons.Add(new Person() { ID = 2, FirstName = "sk", LastName = "uknw" });
        persons.Add(new Person() { ID = 3, FirstName = "wat", LastName = "up" });
        return persons;
    }
}

   The middle one Newtonsoft is nothing but the file for converting into serialization for converting to the json file.

third: This is something really important for converting the text to into ienumeration of serialization format so that a file can be easily carried. name it as PersonList.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;


///

/// Summary description for PageList
///

public class PageList
{
 IEnumerable _rows;
    int _totalRecords;
    int _pageIndex;
    int _pageSize;
    object _userData;


    public PageList(IEnumerable rows, int totalRecords, int pageIndex, int pageSize, object userData)
    {
        _rows = rows;
        _totalRecords = totalRecords;
        _pageIndex = pageIndex;
        _pageSize = pageSize;
        _userData = userData;
    }


    public PageList(IEnumerable rows, int totalRecords, int pageIndex, int pageSize): this(rows, totalRecords, pageIndex, pageSize, null)
    {
    }


    public int total { get { return (int)Math.Ceiling((decimal)_totalRecords / (decimal)_pageSize); } }


    public int page { get { return _pageIndex; } }


    public int records { get { return _totalRecords; } }


    public IEnumerable rows { get { return _rows; } }


    public object userData { get { return _userData; } }


    public override string ToString()
    {
        return Newtonsoft.Json.JsonConvert.SerializeObject(this);
    }
}

  This will make a count and check for number of values according to me yo can actually reuse the file.

Step 3: Now this is some thing really important to call the values json to our asp.net is possible through creating a webservice I m not going to change any name for the web service jst create a web service and use it.

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;


///

/// Summary description for WebService
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{


    public WebService()
    {


        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }


    [WebMethod]
    [ScriptMethod]
    public string GetListOfPersons()
    {
        List persons = JsonHelper.GetPersons();
        return Newtonsoft.Json.JsonConvert.SerializeObject(
            new PagedList(persons, persons.Count, 1, persons.Count));
    }


}


step 4: now Almost our work got over few more step in .aspx file to read data. Things needed before you get through. jqgrid google it nd download latest version also jquery ui, and jqgrid.


head runat="server">
   title>
       script type="text/javascript" src="<%= ResolveClientUrl("~/SyntaxHigligher/scripts/shCore.js") %>">
    script type="text/javascript" src="<%= ResolveClientUrl("~/SyntaxHigligher/scripts/shBrushPlain.js") %>">
    script type="text/javascript" src="<%= ResolveClientUrl("~/SyntaxHigligher/scripts/shBrushCSharp.js") %>">
    script type="text/javascript" src="<%= ResolveClientUrl("~/SyntaxHigligher/scripts/shBrushJScript.js") %>">
    script type="text/javascript">
       SyntaxHighlighter.config.clipboardSwf = '<%= ResolveClientUrl("~/SyntaxHigligher/scripts/clipboard.swf") %>';
        SyntaxHighlighter.all();
    /script>
    link type="text/css" rel="stylesheet" href="<%= ResolveClientUrl("~/SyntaxHigligher/styles/shCore.css") %>" />
    link type="text/css" rel="stylesheet" href="<%= ResolveClientUrl("~/SyntaxHigligher/styles/shThemeDefault.css") %>" /    
     script type="text/javascript" src="<%= ResolveClientUrl("~/scripts/jquery-1.3.2.min.js") %>">
    <% if (false) { %>
    script type="text/javascript" src="<%= ResolveClientUrl("~/scripts/jquery-1.3.2-vsdoc2.js") %>">
    % } %>
     link type="text/css" rel="stylesheet" href="<%= ResolveClientUrl("~/styles/redmond/jquery-ui-1.7.2.custom.css") %>" />    link type="text/css" rel="stylesheet" href="<%= ResolveClientUrl("~/styles/ui.jqgrid.css") %>" />
    link type="text/css" rel="stylesheet" href="<%= ResolveClientUrl("~/styles/ui.multiselect.css") %>" />
    script type="text/javascript" src="<%= ResolveClientUrl("~/scripts/jquery-ui-1.7.2.custom.min.js") %>">
    script type="text/javascript" src="<%= ResolveClientUrl("~/scripts/i18n/grid.locale-en.js") %>">
    script type="text/javascript" src="<%= ResolveClientUrl("~/scripts/jquery.jqGrid.min.js") %>">
    script type="text/javascript" src="<%= ResolveClientUrl("~/scripts/ui.multiselect.js") %>">
     
    
/head>
body>
   
        script type="text/javascript">
            $(function () {
                $("#table").jqGrid({
                    datatype: function (pdata) { getData(pdata); },
                    height: 250,
                    colNames: ['ID', 'First Name', 'Last Name'],
                    colModel: [
            { name: 'ID', width: 60, sortable: false },
            { name: 'FirstName', width: 200, sortable: false },
            { name: 'LastName', width: 200, sortable: false }
            ],
                    imgpath: '<%= ResolveClientUrl("~/styles/redmon/images") %>',
                    caption: "Sample JSON data retrieved from ASMX web services"
                });
            });
            function getData(pData) {
                $.ajax({
                    type: 'POST',
                    contentType: "application/json; charset=utf-8",
                    url: '<%= ResolveClientUrl("~/WebService.asmx/GetListOfPersons") %>',
                    data: '{}',
                    dataType: "json",
                    success: function (data, textStatus) {
                        if (textStatus == "success")
                            ReceivedClientData(JSON.parse(getMain(data)).rows);
                    },
                    error: function (data, textStatus) {
                        alert('An error has occured retrieving data!');
                    }
                });
            }
            function ReceivedClientData(data) {
                var thegrid = $("#table");
                thegrid.clearGridData();
                for (var i = 0; i < data.length; i++)
                    thegrid.addRowData(i + 1, data[i]);
            }
            function getMain(dObj) {
                if (dObj.hasOwnProperty('d'))
                    return dObj.d;
                else
                    return dObj;
            }
   
    
   

    
   

   



   Also in all those scripts I removed the '<' braise snc in blogger it wn't accept. I guess that's all almost ready you can get through your grid with file you wanna to run. 


For ur conviniency I hav also uploaded the file yo can get it here or ping me anytime http://www.4shared.com/file/iGgqtpFQ/josntolearn.html


Happy Coding,
the rEAl Sk




Tuesday, February 1, 2011

The 5 types of programmers

Awesome Code
In my code journeys and programming adventures I’ve encountered many strange foes, and even stranger allies. I’ve identified at least five different kinds of code warriors, some make for wonderful comrades in arms, while others seem to foil my every plan.
However they all have their place in the pantheon of software development. Without a healthy mix of these different programming styles you’ll probably find your projects either take too long to complete, are not stable enough or are too perfect for humans to look upon.

Duct TapeThe code may not be pretty, but damnit, it works!
This guy is the foundation of your company. When something goes wrong he will fix it fast and in a way that won’t break again. Of course he doesn’t care about how it looks, ease of use, or any of those other trivial concerns, but he will make it happen, without a bunch of talk or time-wasting nonsense. The best way to use this person is to point at a problem and walk away.

PerfectionYou want to do what to my code?
This guy doesn’t care about your deadlines or budgets, those are insignificant when compared to the art form that is programming. When you do finally receive the finished product you will have no option but submit to the stunning glory and radiant beauty of perfectly formatted, no, perfectly beautiful code, that is so efficient that anything you would want to do to it would do nothing but defame a masterpiece. He is the only one qualified to work on his code.

Anti-ProgrammingI’m a programmer, damnit. I don’t write code.
His world has one simple truth; writing code is bad. If you have to write something then you’re doing it wrong. Someone else has already done the work so just use their code. He will tell you how much faster this development practice is, even though he takes as long or longer than the other programmers. But when you get the project it will only be 20 lines of actual code and will be very easy to read. It may not be very fast, efficient, or forward-compatible, but it will be done with the least effort required.

Half-assedWhat do you want? It works doesn’t it?
The guy who couldn’t care less about quality, that’s someone elses job. He accomplishes the tasks that he’s asked to do, quickly. You may not like his work, the other programmers hate it, but management and the clients love it. As much pain as he will cause you in the future, he is single-handedly keeping your deadlines so you can’t scoff at it (no matter how much you want to).

TheoreticalWell, that’s a possibility, but in practice this might be a better alternative.
This guy is more interested the options than what should be done. He will spend 80% of his time staring blankly at his computer thinking up ways to accomplish a task, 15% of his time complaining about unreasonable deadlines, 4% of his time refining the options, and 1% of his time writing code. When you receive the final work it will always be accompanied by the phrase “if I had more time I could have done this the right way”.


Thursday, January 6, 2011

Cracking Google Transulator

Felt Boring from the night did so many craps with the Google Translator now with some kind of entertaining stuff

1) Go to http://translate.google.com

2) Paste the following Code "pv zk bschk pv zk pv bschk zk pv zk bschk pv zk pv bschk zk bschk pv bschk bschk pv kkkkkkkkkk bschk"

3) Now Set Language Both to German

4) click on BeatBox


Follow these steps yo vl enjoy the fun.