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
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.
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..
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
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.
I know that it is the best to use ItemBound ot ItemCreate , but in my case I can't used it?
Thanks,
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.