Thursday, April 25, 2013

Fix:find label inside FooterTemplate RadGrid Javascript

Hi, Here is an easy way to find label text inside Footer

In .aspx page

 <FooterTemplate>
                                        <asp:Label ID="lblFooterValue"  Font-Bold="true" ForeColor="Green" Font-Size="15px"  runat="server" Text="0"></asp:Label>
                                    </FooterTemplate>


 <ClientSettings>
<Scrolling UseStaticHeaders="True" AllowScroll="True"></Scrolling>
 </ClientSettings>



In Javascript

var grid = $find("<%=RadGrid1.ClientID %>");
                          var MasterTable = grid.get_masterTableView();
                var footerTable = grid.get_masterTableViewFooter().get_element();
  var label = $telerik.findElement(footerTable, "lblFooterValue");


Thanks

Wednesday, April 3, 2013

Close RadWindow on Escape Key Press

Hi , Here I will tell you that how to close RadWindow on Escape Key Press


 <script type="text/javascript">        
       document.onkeydown = function(evt)
       {
        evt = evt || window.event;
        if (evt.keyCode == 27) {
        var oWnd = $find("<%= RadWindow1.ClientID %>");
        oWnd.close();    
        }
       };

</script>

Thanks.

Thursday, March 21, 2013

Get DataKeyName of Radgrid server side

Hii,  Here a Very Easy way to find datakeyname value of Radgrid

 int intItemIndex = e.Item.ItemIndex; ;
            int intMyID = Convert.ToInt32(Radgrid.MasterTableView.Items[intItemIndex].GetDataKeyValue("Id").ToString());

Thursday, March 14, 2013

Find Control Value on RadGrid ItemCommand

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if (e.CommandName == "some_command")  
        {  
            GridEditFormItem editform = (GridEditFormItem)((Telerik.Web.UI.GridDataItem)(e.Item)).EditFormItem;  
            TextBox txtbx = (TextBox)editform.FindControl("MyTextbox");  
            string strtxt = txtbx.Text;  
        }  
    }  

Friday, September 14, 2012

Hiding AutoGenerateEdit column False Telerik codeBehind

Hii,  If you have set AutoGenerateEditColumn of RadGrid to true
Now under such condition You need to hide auto generate column to False.So you can do it on item dat bound


protected void RadGrid3_ItemDataBound(object sender, GridItemEventArgs e)
    {

if (e.Item is GridDataItem)
            {

                GridDataItem editItem = (GridDataItem)e.Item;
((LinkButton)editItem["AutoGeneratedEditColumn"].Controls[0]).Visible = false;
}


}

Thursday, September 6, 2012

Print Only Radgrid with paging content

Hii, I am going to tell you that how you can Print RadGrid as paging enabled.Generally when we print Radgrid then it prints only that data which is visible to you ,Means it will print only that page data..To print the whole data inside RadGrid so Lets Have some Code

We have to take RadAjaxPanel for that


 <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
    <div class="wrapper">
        <div class="topBar">
            <p class="headingText">
                <asp:LinkButton ID="LinkButton1" runat="server" type="button" Text="[ Print Grid ]"
                    OnClick="LinkButton1_Click" Font-Underline="false" ForeColor="Black" /></p>
            This code-library demonstrates how to print RadGrid without surrounding content<br />
        </div>
        <telerik:RadGrid ID="radGrid1" runat="server" Skin="Simple" DataSourceID="SqlDataSource1"
            Style="margin: 20px;" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True"
            GridLines="None">
        </telerik:RadGrid>
    </div>
    </telerik:RadAjaxPanel>


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT * from Subject_tab">
    </asp:SqlDataSource>

Now  in Javascript code

 <script type="text/javascript">
        function getOuterHTML(obj) {
            if (typeof (obj.outerHTML) == "undefined") {
                var divWrapper = document.createElement("div");
                var copyOb = obj.cloneNode(true);
                divWrapper.appendChild(copyOb);
                return divWrapper.innerHTML
            }
            else {
                return obj.outerHTML;
            }
        }

        function PrintRadGrid() {
            var radGrid = $find('<%= radGrid1.ClientID %>');
            var previewWindow = window.open('about:blank', '', '', false);
            var styleSheet = '<%= Telerik.Web.SkinRegistrar.GetWebResourceUrl(this, radGrid1.GetType(), String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css", radGrid1.Skin)) %>';
            var baseStyleSheet = '<%= Telerik.Web.SkinRegistrar.GetWebResourceUrl(this, radGrid1.GetType(), "Telerik.Web.UI.Skins.Grid.css") %>';
            var htmlContent = "<html><head><link href = '" + styleSheet + "' rel='stylesheet' type='text/css'></link>";

            htmlContent += "<link href = '" + baseStyleSheet + "' rel='stylesheet' type='text/css'></link></head>";
            htmlContent = htmlContent + "<body>" + getOuterHTML(radGrid.get_element()) + "</body></html>";
            previewWindow.document.open();
            previewWindow.document.write(htmlContent);
            previewWindow.document.close();
            previewWindow.print();

            if (!$telerik.isChrome) {
                previewWindow.close();
            }
        }
    </script>


And Finally the Code in .Cs Page.


protected void LinkButton1_Click(object sender, EventArgs e)
    {
        radGrid1.AllowPaging = false;
        radGrid1.Rebind();

        foreach (GridItem item in radGrid1.MasterTableView.GetItems(new GridItemType[] { GridItemType.Pager, GridItemType.FilteringItem }))
            item.Display = false;

        RadAjaxPanel1.ResponseScripts.Add("PrintRadGrid('" + radGrid1.ClientID + "')");
    }
    protected void radGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "EnablePaging")
        {
            radGrid1.AllowPaging = true;
            radGrid1.Rebind();
        }
    }



Thursday, August 23, 2012

Find Footer Text of RadGrid

Hiii Guys....Now i will tell you that how can you find Footer text of Radgrid.Just Follow two steps


protected void RadGrid3_ItemDataBound(object sender, GridItemEventArgs e)
    {



         if (e.Item is GridFooterItem)
        {
             GridFooterItem ft = (GridFooterItem)e.Item;
            string cx = ft["Your Column Unique Name"].Text;
        }

}