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. }

May 24, 2007

Truncate a string without breaking a word

function truncate_str($string, $length = 80, $etc = '...',$break_words = false)
{
if ($length == 0)
return '';
if (strlen($string) > $length) {
$length -= strlen($etc);
if (!$break_words)
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
return substr($string, 0, $length).$etc;
} else
return $string;
}