This is a migrated thread and some comments may be shown as answers.

Sort Image

6 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hay
Top achievements
Rank 1
hay asked on 29 Jan 2009, 09:52 PM
Ok .. I have a problem ..I have sort Image added from code behind..Now the  Image they wanted is little bigger then the default image..
 there are about 20 columns in the grid..The problem is that when the header text is longer image doesn't fix the column size it wraps and adds another header row just for the image...I also have a filter row ..All together there are 3 header row  now ..header txt,sort image and filter.. I was wondering if I can put the image infront of the filter ...like sort image,filter Box and filter image ? so that I am limited to only two header row

thanks,
Hay

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Jan 2009, 04:52 AM
Hi Hay,

 I would suggest  you to use the FilterTemplate so that you can design the FilteringItem accordingly.

ASPX:
 <telerik:GridBoundColumn DataField="ProductName"    HeaderText="ProductName" SortExpression="ProductName" 
                            UniqueName="ProductName"   > 
                             <FilterTemplate> 
                                <asp:TextBox ID="FiterTextBox1" runat="server"></asp:TextBox> 
                                <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/RadControls/Skins/Hay/Grid/Filter.gif" /> 
                            </FilterTemplate> 
                        </telerik:GridBoundColumn> 


You can also add any control dynamically in the FilterTemplate as shown below.

CS:
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridFilteringItem) 
        { 
            GridFilteringItem filter = (GridFilteringItem)e.Item; 
            Image img = new Image(); 
            img.ID = "Image1"
            img.ImageUrl = "Image1.gif"
            filter["ProductName"].Controls.AddAt(0, img); 
        } 
    } 


Thanks
Shinu.
0
hay
Top achievements
Rank 1
answered on 30 Jan 2009, 02:56 PM
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridFilteringItem) 
        { 
            GridFilteringItem filter = (GridFilteringItem)e.Item; 
            Image img = new Image(); 
            img.ID = "Image1"
            img.ImageUrl = "Image1.gif"
            filter["ProductName"].Controls.AddAt(0, img); 
        } 
    }

This is so what I need ..I can do little twist and turn to fix the result I need...Only one Question more ..If I have to take care in
page PreRender can I get to the GridFilteringItem?
 protected ovveride  void page_PreRender(EventArgs e
    {
        RadGrid1.MasterTableView....   (Something) 
}

Thanks alot for the help above..
hay..
0
hay
Top achievements
Rank 1
answered on 30 Jan 2009, 07:54 PM

 

protected override void OnPreRender(EventArgs e)

 

{

 

    if(RadGrid1.MasterTableView.SortExpressions.Equals(RadGrid2.MasterTableView.SortExpressions))

 

    {    
        Image
img = null;

 

 

 

        GridSortExpression Exp = null;

 

        GridItem

[] collec1 = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem);

 

 

        GridFilteringItem filter1 = collec[0] as GridFilteringItem;
         GridItem[]  collec2 = RadGrid2.MasterTableView.GetItems(GridItemType.FilteringItem);

        GridFilteringItem filter2 = collec[0] as GridFilteringItem;

        

 

        img = new Image();

 

        img.ID = "Image1" + i.ToString();

 

        if (Exp.SortOrder == GridSortOrder.Ascending) img.ImageUrl = "SortAsc1.gif";

 

        else if (Exp.SortOrder == GridSortOrder.Descending) img.ImageUrl = "SortDesc1.gif";

 

        filter1["Name"].Controls.AddAt(0, img); 
       
        img = new Image();

 

        img.ID = "Image2" + i.ToString();

 

        if (Exp.SortOrder == GridSortOrder.Ascending) img.ImageUrl = "SortAsc1.gif";

 

         else if (Exp.SortOrder == GridSortOrder.Descending) img.ImageUrl = "SortDesc1.gif";

 

        filter2["Name"].Controls.AddAt(0, img);

        } 

        RadGrid1.MasterTableView.Rebind();

        RadGrid2.MasterTableView.Rebind();


}

now the Sorting works , but the only problem is that I can't add the Image to the filter portion..It will work on the ItemDataBound , but  I can't get to the GridFiteringItem  of the another Grid?

How can i make this work..

thansk,
DIP
0
Iana Tsolova
Telerik team
answered on 02 Feb 2009, 04:09 PM
Hi hay,

When you need to add controls into RadGrid cells, I suggest that you do it on ItemCreated or on ItemDataBound events. And in this case you do not need to Rebind() the grid on PreRender.

I hope this helps.

Best wishes,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
hay
Top achievements
Rank 1
answered on 02 Feb 2009, 04:25 PM
So you mean to say that .....There is no were we can insert an image on the preRender ?
I know that it is the best to use ItemBound ot ItemCreate , but in my case I can't used it?

Thanks,
hay 
0
Iana Tsolova
Telerik team
answered on 04 Feb 2009, 10:12 AM
Hi hay,

Yes, I am afraid you cannot add the image to the grid cells controls collection on PreRender or if you however add it, it might not function as expected.
Therefore I would suggest you to add desired images on ItemCreated/ItemDataBound and only set their properties on PreRender, eg. set their visibility, image source, etc.

I hope this helps.
 
Best wishes,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
hay
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
hay
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or