Monday 16 February 2015

Sort a DataTable by a specific column using C# | pravin prajapati

How to Sort a DataTable by a specific column using C#


using System.Data;

//create our datatable and setup with 2 columns
DataTable dt = new DataTable();
dt.Columns.Add("CustomerFirstname", typeof(string));
dt.Columns.Add("CustomerSurname", typeof(string));
DataRow dr;

//store some values into datatable
//just using 2 names as example
dr = dt.NewRow();
dr["CustomerFirstname"] = "John";
dr["CustomerSurname"] = "Murphy";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["CustomerFirstname"] = "John";
dr["CustomerSurname"] = "Doe";
dt.Rows.Add(dr);

//check to make sure our datatable has at
//least one value. For this example it's not
//really need but if we were taking the 
//values from a database then this would be
//very important!
if (dt.Rows.Count > 0)
{
   //convert DataTable to DataView
   DataView dv = dt.DefaultView;
   //apply the sort on CustomerSurname column
   dv.Sort = "CustomerSurname";
   //save our newly ordered results back into our datatable
   dt = dv.ToTable();
}

//display your datatable to the user by databinding
//to repeater/gridview
reference from http://www.reddybrek.com/post/how-to-sort-a-datatable-by-a-specific-column-using-c
hope it's help u..:)

thank you..!!

Monday 19 January 2015

Add custom action link to jqGrid row | pravin pajapati


Add custom action link to jqGrid row.

function showDetail(id){
//do somthing here...
alert(id);
}

colNames: ['ID',''],
 colModel: [
    { name: "ID", key: true, index: "ID", sortable: false, hidden: true }
                  ,{ name: 'action', align: 'center', width: 25, sortable: false
                      , title: false, fixed: true, search: false
                      , formatter: function (cellvalue, options, rowObject) 
                      { var stImageLinks = '<a title="action tooltip" 
                             onclick="showDetail(\'' + (rowObject.ID) + '\') + '\');"
       href="#"><img src="../images/edit.png" /></a>';
                                            return stImageLinks;
                                        }
                                    }
  },

hope it's useful for you. thank you. Pravin Prajapati

Saturday 1 February 2014

Remove all cookies from browser in c# | Pravin Prajapati

Remove all cookies from browser in c#

Create Method

 protected void removeCookie()
        {
            HttpCookie aCookie;
            string cookieName;
            int limit = Request.Cookies.Count;
            for (int i = 0; i < limit; i++)
            {
                cookieName = Request.Cookies[i].Name;
                aCookie = new HttpCookie(cookieName);
                aCookie.Expires = DateTime.Now.AddDays(-1);
                aCookie.Value = string.Empty;
                Response.Cookies.Add(aCookie);
            }
        }

Call Method

 protected void Page_Load(object sender, EventArgs e)
        {
            removeCookie(); //call method here
        }

Wednesday 15 January 2014

Compare Date,Time in Sql, Comapre date,Compare time in Sql | Pravin Prajapati


  Compare Date/Time with Currant Date/Time in Sql

SELECT COUNT(*)

FROM tablename

WHERE
--compare date here with current date.
 CONVERT(DATE, [dateTimeColumn]) = CONVERT(DATE, GETDATE())
--compare time here with current time
 AND CONVERT(TIME, [dateTimeColumn]) <= CONVERT(TIME, GETDATE())