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

}

Friday, July 20, 2012

Find selected row of RadGrid on buttonclick


 protected void btn_submit_Click(object sender, EventArgs e)
    {

        foreach (GridDataItem item in RadGrid1.SelectedItems)
        {          
            string custoID = item.GetDataKeyValue("Branch_code").ToString(); //you have to set DataKeyNames value to the column whose value you have to find
        }
    }

Tuesday, June 26, 2012

Find and Update Control Values before InsertForm of Radgrid Opens

Suppose if You wants to change RadDatePicker Min date which is inside insert Item

So before the form OPens You can change this value On RadGrid Item Command

 protected void RadGrid3_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.InitInsertCommandName)
        {

            e.Canceled = true;            
            System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();            
            e.Item.OwnerTableView.InsertItem(newValues);
            string selected = RadYear.SelectedItem.Text;
            GridEditableItem insertItem = e.Item.OwnerTableView.GetInsertItem();
            RadDatePicker dtt = (RadDatePicker)insertItem.FindControl("RadDatePicker3") as RadDatePicker;
            dtt.MinDate = Convert.ToDateTime(selected + "-01-01");
            dtt.MaxDate = Convert.ToDateTime(selected + "-12-31");
        }
    }