Showing posts with label Extension Methods. Show all posts
Showing posts with label Extension Methods. Show all posts

Monday, August 9, 2010

Retrieving selected row's key from Telerik RadGrid

This approach easily gets old:

TextBox1.Text = grdCategory.SelectedItems[0].OwnerTableView.DataKeyValues[grdCategory.SelectedItems[0].ItemIndex]["category_id"].ToString();

To make retrieving of key simpler for single select and single key on RadGrid, make an extension method for it:

public static class Helper
{
    public static object SingleSelectKeyValue(this Telerik.Web.UI.RadGrid rg)
    {
        return rg.SelectedItems[0].OwnerTableView.DataKeyValues[rg.SelectedItems[0].ItemIndex][rg.MasterTableView.DataKeyNames[0]];
    }
}

To use:

protected void grdCategory_SelectedIndexChanged(object sender, EventArgs e)
{
    TextBox1.Text = grdCategory.SingleSelectKeyValue().ToString();
}

Wednesday, June 23, 2010

First foray to jQuery

<head>
<script src="jquery-1.4.4.js"></script>
 

<script type="text/javascript">    
 $(function() {     
  var toggle = true;

  $("a").click(function() {        
   $("p.neat").showIt(toggle,"fast");    
   toggle = !toggle;
   return false;
  });

  $.fn.showIt = function(b,param) { 
   if (b) 
    $(this).hide(param);
   else     
    $(this).show(param);
  };


 });

 $("p.neat").hide();   
</script>
 
</head>
 
<body>

 <p class="neat" style="width: 200">
 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
 </p>
 
 <a href="/">Yeah</a> 
</body>

Tuesday, June 1, 2010

Wednesday, March 31, 2010

Suppress Crystal Report Viewer's Main Report Tab

public static void SuppressReportTabs(
    this CrystalDecisions.Windows.Forms.CrystalReportViewer crv)
{
    foreach (System.Windows.Forms.Control control in crv.Controls)
        if (control is CrystalDecisions.Windows.Forms.PageView)
        {
            var tab = 
                (control as CrystalDecisions.Windows.Forms.PageView)
                .Controls[0] as System.Windows.Forms.TabControl;

            tab.ItemSize = new System.Drawing.Size(0, 1);
            tab.SizeMode = System.Windows.Forms.TabSizeMode.Fixed;
            tab.Appearance = System.Windows.Forms.TabAppearance.Buttons;
        }
}