RadGrid for ASP.NET

Setting filter textbox dimensions/changing default filter image Send comments on this topic.
Filtering > How to > Setting filter textbox dimensions/changing default filter image

Glossary Item Box

In some cases you may want to change the default filter textbox height/width to prevent the wrapping/hiding of the filter menu image. This is convenient when you set fixed widths for your grid columns, allow column resizing (AllowColumnResize = true), etc. Additionally, you might prefer to change the url for the default filter menu image with your custom one.

For this purpose hook the ItemCreated event of the grid to customize the dimensions of the filter boxes/modify the filter images. All you have to do is check whether the item is of type GridFilteringItem, retrieve reference to the TextBox/Image inside this item for the respective column, and change its width/height/ImageUrl according to your appearance conventions. Here is a sample approach:

C# Copy Code
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
        
if (e.Item is GridFilteringItem)
       {
           GridFilteringItem filteringItem = e.Item
as GridFilteringItem;

           
//set dimensions for the filter textbox
           
TextBox box = filteringItem["ContactName"].Controls[0] as TextBox;
           box.Width = Unit.Pixel(30);
          
//set ImageUrl which points to your custom image
          
Image image = filteringItem["ContactName"].Controls[1] as Image;
         image.ImageUrl =
"<my_image_url>";
       }
}
VB.NET Copy Code
Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemCreated
   If TypeOf e.Item Is GridFilteringItem Then
      Dim filteringItem As GridFilteringItem = CType(e.Item, GridFilteringItem)

      'set dimensions for the filter textbox
      Dim box As TextBox = CType(filteringItem("ContactName").Controls(0), TextBox)
      box.Width = Unit.Pixel(30)
      'set ImageUrl which points to your custom image
      Dim image As Image = CType(filteringItem("ContactName").Controls(1), Image)
     image.ImageUrl = "<my_image_url>"
   End If
End Sub 'RadGrid1_ItemCreated