July 18, 2007

Check if connected to internet

Once I stuck with a problem that "How to check if connected to internet or not using JavaScript"
There could be different reasons for this kind of need.

1. Suppose one need to call an online script from JavaScript code
2. Start downloading a file etc

  1. if(there is NO internet connectivity){
  2. window.close();
  3. }
  4. else{
  5. Call a script OR download a file etc
  6. }


Solution is very simple. Simply Put an image tag in your HTML file and write code like this:

  1. <img src="online-site-url/image.gif" onError="alert('Image missing or no internet connection')">


I hope it will help you guys.

July 3, 2007

Delete Duplicate records

The scenario is:

The table has 3 columns, A, B, and C. Column A is unique for all rows
but the columns B and C can be duplicate across rows.
And it needs to remove the rows where B and C are duplicated.

DELETE
FROM tbl_name
WHERE
a NOT IN
(
SELECT
MIN(a)
FROM daTable
GROUP BY b,c
)

May 31, 2007

Return Selected checkbox values

  1. public Hashtable returnGridSelectedIds(GridView gv1, string chkBoxField)
  2. {
  3. string Id = "";
  4. Hashtable ht = new Hashtable();
  5. if (gv1.Rows.Count > 0)
  6. {
  7. foreach (GridViewRow gvr in gv1.Rows)
  8. {
  9. HtmlInputCheckBox htmChkBox = (HtmlInputCheckBox)gvr.FindControl(chkBoxField);
  10. if (htmChkBox.Checked)
  11. Id += htmChkBox.Value + ",";
  12. }
  13. }
  14. if (Id.ToString() != "")
  15. Id = Id.Substring(0, Id.Length - 1);
  16. ht["Ids"] = Id;
  17. return ht;
  18. }