protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) { if (!string.IsNullOrEmpty(e.Column.UniqueName) && !string.IsNullOrEmpty(e.Column.HeaderText)) e.Column.HeaderText = e.Column.UniqueName; //OR e.Column.HeaderText = e.Column.HeaderText.Replace(" ", ""); }
Tuesday, 26 June 2012
Space added in autoGenerated column header problem in Radgrid
Wednesday, 20 June 2012
Customizing items of RadGrid page size combo based on total records
Telerik provides the easy to use RadGrid control with inbuilt paging feature.
By default paging combo includes 10, 20 and 50 page sizes, regardless of number of records displayed in the grid (i.e. if records counts to 11 then also page size combo displays 10, 20 and 50).
If we want to customize the page size combo items to show
In order to achieve the above functionality, we will be using RadGrid ItemCreated and ItemEvent events, refer the below code.
Displaying page combo always regardless of number of records, refer below code
Showing "Show All" option in page size combo, refer below combo
By default paging combo includes 10, 20 and 50 page sizes, regardless of number of records displayed in the grid (i.e. if records counts to 11 then also page size combo displays 10, 20 and 50).
If we want to customize the page size combo items to show
- Records count > 10 then page size items should show 10 and 20
- Records count >= 20 then page size items should show 10, 20 and 50
In order to achieve the above functionality, we will be using RadGrid ItemCreated and ItemEvent events, refer the below code.
private int totalItemCount; protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e) { if (e.EventInfo is GridInitializePagerItem) { totalItemCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount; } } protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridPagerItem) { GridPagerItem pagerItem = (GridPagerItem)e.Item; RadComboBox pageSizeCombo = (RadComboBox)pagerItem.FindControl("PageSizeComboBox"); for (int i = 0; i < pageSizeCombo.Items.Count; i++) { RadComboBoxItem item = pageSizeCombo.Items[i]; if (Convert.ToInt32(item.Value) > totalItemCount) { i--; pageSizeCombo.Items.Remove(item.Index); } } if (totalItemCount != Convert.ToInt32(pageSizeCombo.Items[pageSizeCombo.Items.Count - 1].Value)) { RadComboBoxItem item = new RadComboBoxItem(); item = new RadComboBoxItem(totalItemCount.ToString(), totalItemCount.ToString()); item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID); pageSizeCombo.Items.Add(item); } // If you lost selected value in Pagesize combo //pageSizeCombo.FindItemByValue(e.Item.OwnerTableView.PageSize.ToString()).Selected = true; } }
<telerik:radgrid allowpaging="true" id="RadGrid1" runat="server"> <mastertableview> <pagerstyle alwaysvisible="true"></pagerstyle> . . . . . . . . </mastertableview> </telerik:radgrid>
private int totalItemCount; protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e) { if (e.EventInfo is GridInitializePagerItem) { totalItemCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount; } } protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridPagerItem) { GridPagerItem pagerItem = (GridPagerItem)e.Item; RadComboBox PageSizeCombo = (RadComboBox)pagerItem.FindControl("PageSizeComboBox"); RadComboBoxItem item1 = new RadComboBoxItem(); item1 = new RadComboBoxItem("Show All", totalItemCount.ToString()); item1.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID); PageSizeCombo.Items.Add(item1); } }
Monday, 11 June 2012
what is the difference between Response.Redirect and Response.RedirectPermanent?
Response.Redirect
If you use the Response.Redirect() to redirect from Page A to Page B, search engines will keep Page A in their index since the Response.Redirect() indicates a temporary redirect. In case the original page (Page A) no longer exists, and Page B should replace Page A.The Response.Redirect generates Response code as 302.
Response.RedirectPermanent
While in Response.RedirectPermanent to redirect from Page A to Page B, search engines will keep Page B in their index since the Response.RedirectPermanent() indicates a permanant redirect.The Response.RedirectParmanent generates Response code as 301.
What is the difference between permanent and temporary redirect?
Permanent 301
To summarize in a few lines, permanent 301 redirects are just as they sound. They are permanent redirects from an old URL to a new one. These redirects tell the search engines that the old location is to be removed from their index and replaced with the new location. Using 301 redirects is the most search engine friendly way to redirect traffic and engines, and far out weighs that of various JavaScript and Meta refresh redirects.
Temporary 302
Temporary 302 redirects are also as they sound; temporary. Here you are telling the search engines to read and use the content on the new page, but to keep checking the original URL first as it will ultimately be reestablished.
So, main deference between Response.Redirect() and Response.RedirectPermanent() is related to SEO.
If you use the Response.Redirect() to redirect from Page A to Page B, search engines will keep Page A in their index since the Response.Redirect() indicates a temporary redirect. In case the original page (Page A) no longer exists, and Page B should replace Page A.The Response.Redirect generates Response code as 302.
Response.RedirectPermanent
While in Response.RedirectPermanent to redirect from Page A to Page B, search engines will keep Page B in their index since the Response.RedirectPermanent() indicates a permanant redirect.The Response.RedirectParmanent generates Response code as 301.
What is the difference between permanent and temporary redirect?
Permanent 301
To summarize in a few lines, permanent 301 redirects are just as they sound. They are permanent redirects from an old URL to a new one. These redirects tell the search engines that the old location is to be removed from their index and replaced with the new location. Using 301 redirects is the most search engine friendly way to redirect traffic and engines, and far out weighs that of various JavaScript and Meta refresh redirects.
Temporary 302
Temporary 302 redirects are also as they sound; temporary. Here you are telling the search engines to read and use the content on the new page, but to keep checking the original URL first as it will ultimately be reestablished.
So, main deference between Response.Redirect() and Response.RedirectPermanent() is related to SEO.
Subscribe to:
Posts (Atom)