Saturday, 30 March 2013

asp.net grid view sorting in linq to sql



  public void bindGrid()
    {
        REGISTRATIONDataContext objDB = new REGISTRATIONDataContext();
        var listuser = (from p in objDB.REGISTRATIONs
                       select p).ToArray();
       
        if (listuser != null)
        {
            if (GridViewSortDirection == SortDirection.Ascending)
            {
                GridView1.DataSource = listuser.OrderBy(x => x.GetType().GetProperty(GridViewSortExpression).GetValue(x, null)).ToList();
            }
            else
            {
                GridView1.DataSource = listuser.OrderByDescending(x => x.GetType().GetProperty(GridViewSortExpression).GetValue(x, null)).ToList();
            };
        }
        else
        {
            GridView1.DataSource = null;
        }
        //GridView1.DataSource = listuser;
        GridView1.DataBind();
    }



 public string GridViewSortExpression
    {
        get
        {
          return ViewState["GridViewSortExpression"] == null ? "NAME":ViewState["GridViewSortExpression"] as string;    
        }
        set
        {
            ViewState["GridViewSortExpression"] = value;
        }
    }

    public SortDirection GridViewSortDirection
    {
        get
        {
            if (ViewState["sortDirection"] == null)
                ViewState["sortDirection"] = SortDirection.Ascending;

            return (SortDirection)ViewState["sortDirection"];
        }
        set { ViewState["sortDirection"] = value; }
    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {

        GridViewSortExpression = e.SortExpression;
        if (GridViewSortDirection == SortDirection.Ascending)
        {
            GridViewSortDirection = SortDirection.Descending;
        }
        else
        {
            GridViewSortDirection = SortDirection.Ascending;
        };
        bindGrid();  
    }

Monday, 25 March 2013

html5 File Api & Read file in Javascript

 <style>
  .thumb {
    height: 75px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
</style>

<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }

      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

Sunday, 3 March 2013

The difference between trigger() and triggerHandler()




<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("input").select(function(){
    $("input").after(" Text marked!");
  });
  $("#btn1").click(function(){
    $("input").trigger("select");
  });
  $("#btn2").click(function(){
    $("input").triggerHandler("select");
  });
});
</script>
</head>
<body>

<p>Click each button to see the difference between trigger() and triggerHandler().
<br><br>
<input type="text" value="Hello World">
<br><br>
<button id="btn1">trigger()</button>
<button id="btn2">triggerHandler()</button>

</body>
</html>

trigger() is call a internel code of select event and select a textbox
The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements.

triggerHandler() is call internel code of select event ,but textbox is not select