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

Custom Skin, Filters and type being output in templatecolumn

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
darren
Top achievements
Rank 1
darren asked on 11 Mar 2009, 10:13 PM
Hi all,

I am just getting to grips with the RadGrid and trying to style it with my own skin. though having some really strange problems...

Code is below, though a quick explanation..
The RadGrid is bound to a List<custom object> and binds all well and good
Sorting is enabled and works well
Paging is enabled and works well
Filtering is enabled though this is where is starts to get a little funky...

I want the filter to appear on only certain columns, so set AllowFiltering="True" on the GridBoundColumn in the skin file - this works
I then set the AllowFiltering="false" on the GridTemplateColumn as these only contain buttons that i don't want/need to filter

If a default skin is applied then the content of this template column contains 2 buttons that are built and applied during the OnItemDataBound event.

As soon as i wish to use my custom skin via the SKinId then an additional column appears to the right of my buttons column containing the string value for the type that is being used in the grid - in this case "BoxOfficeBO.BLL.BL.UserProxy". This additional column contains the filters though the filter images is not found

The skin is only in its infant stage at the moment, next to nothing applied.

I know there are many ways to create the buttons for the rows, though at the time this best suits the need; though will re-factor if this is what is causing the issue.

So, how do i:
    A) Hide the filter options for certain columns and not others
    B) stop the type being output as a string in the template when custom skining?


Any ideas would be great.

Cheers

ASPX Code:

<telerik:RadGrid ID="SummaryGrid" runat="server" EnableEmbeddedSkins="false" SkinID="AdminGrid" 
                 AutoGenerateColumns="False" AllowSorting="true"   
                 GridLines="Both" BorderColor="Black" BackColor="gray" AllowPaging="True" PageSize="5" OnItemDataBound="BindRows" > 
 
<MasterTableView AllowFilteringByColumn="True" > 
    <Columns> 
        <telerik:GridBoundColumn DataField="Title" HeaderText="Title" SortExpression="Title"  UniqueName="Title" ItemStyle-Width="5%"  ></telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Forename" HeaderText="Forename" SortExpression="Forename" UniqueName="Forename" ItemStyle-Width="20%" ></telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Surname" HeaderText="Surname" SortExpression="Surname"  UniqueName="Surname" ItemStyle-Width="20%"></telerik:GridBoundColumn> 
        <telerik:GridHyperLinkColumn DataTextField="Email" SortExpression="Email" DataNavigateUrlFormatString="mailto:{0}" DataNavigateUrlFields="Email"  HeaderText="Email" UniqueName="Email"  ItemStyle-Width="20%"></telerik:GridHyperLinkColumn> 
        <telerik:GridTemplateColumn  AllowFiltering="true" UniqueName="Locked" > 
            <HeaderTemplate> 
                <asp:Label runat="server" ID="userlockedheader" Text="Enabled" /> 
            </HeaderTemplate> 
            <ItemTemplate> 
                <asp:Image runat="server" ID="LockedImage" /> 
            </ItemTemplate> 
        </telerik:GridTemplateColumn> 
        <telerik:GridBoundColumn DataField="LastAccessed" SortExpression="LastAccessed"  HeaderText="Last Login"  UniqueName="LastAccessed" ItemStyle-Width="20%"></telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="RoleName"  HeaderText="Role" SortExpression="Role"  UniqueName="RoleName" ItemStyle-Width="20%"></telerik:GridBoundColumn> 
        <telerik:GridTemplateColumn HeaderText="Actions">  
            <ItemTemplate> 
                <asp:Panel runat="server" ID="ActionsPanel"></asp:Panel> 
            </ItemTemplate> 
        </telerik:GridTemplateColumn> 
    </Columns> 
</MasterTableView> 
 
</telerik:RadGrid>  


Code behind for itemDataBound

 protected void BindRows(object sender, GridItemEventArgs e)  
        {  
                        
            if (e.Item is GridDataItem)  
            {  
                UserProxy user = (UserProxy)e.Item.DataItem;  
                if (user != null)  
                {  
                    Image locked = e.Item.FindControl("LockedImage"as Image;  
                    locked.ImageUrl = (user.IsLocked) ? ThemePath + "images/icons/false.png" : ThemePath + "images/icons/true.png";  
                }  
                                  
                // Delete Button  
                if (CanDelete)  
                {                     
                    Panel ActionsPanel =  (Panel)e.Item.FindControl("ActionsPanel");                      
                    ImageButton DeleteBtn = new ImageButton();  
                    DeleteBtn.ImageUrl = ThemePath + "images/icons/delete16.png";  
                    DeleteBtn.ToolTip = "Delete User";  
                    DeleteBtn.ID = "delete_" + e.Item.RowIndex.ToString();  
                    DeleteBtn.CommandArgument = "delete_" + user.UserId.ToString();  
                    DeleteBtn.Command += new CommandEventHandler(ActionButtonClicked);  
                    DeleteBtn.CssClass = "ActionButton";  
                    DeleteBtn.OnClientClick = "return ConfirmMessage('" + Resources.CommonMessages.ConfirmDeleteBefore + " " + user.Forename + " " + user.Surname + "" + Resources.CommonMessages.ConfirmDeleteAfter + "')";  
                    DeleteBtn.Attributes.Add("onMouseOver""return WindowStatus('Delete User " + user.Forename + " " + user.Surname + "')");  
                    DeleteBtn.Attributes.Add("onMouseOut""return WindowStatus('')");  
                    ActionsPanel.Controls.Add(DeleteBtn);                      
                }  
 
                // View Button  
                ImageButton ViewBtn = new ImageButton();  
                ViewBtn.ImageUrl = ThemePath + "images/icons/open16.png";  
                ViewBtn.ToolTip = "Open User";  
                ViewBtn.ID = "open_" +  e.Item.RowIndex.ToString();  
                ViewBtn.CommandArgument = "open_" + user.UserId.ToString();  
                ViewBtn.Command += new CommandEventHandler(ActionButtonClicked);  
                ViewBtn.CssClass = "ActionButton";  
                ViewBtn.Attributes.Add("onMouseOver""return WindowStatus('Open User " + user.Forename + " " + user.Surname + "')");  
                ViewBtn.Attributes.Add("onMouseOut""return WindowStatus('')");  
                ((Panel)e.Item.FindControl("ActionsPanel")).Controls.Add(ViewBtn);  
            }  
               
        } 


Skin in INFANT stage -

<telerik:RadGrid  runat="server" SkinID="AdminGrid" ImagesPath="~/app_themes/admin theme/images/icons/">  
 
<MasterTableView>      
    <Columns> 
        <telerik:GridBoundColumn ShowSortIcon="true" AllowFiltering="true" FilterImageToolTip="Filter" FilterImageUrl="filter.gif"></telerik:GridBoundColumn> 
        <telerik:GridTemplateColumn AllowFiltering="false" ></telerik:GridTemplateColumn> 
    </Columns> 
</MasterTableView> 
<FilterItemStyle  /> 
<HeaderStyle BackColor="#C1DFFD" Font-Bold="False" Font-Size="12px" ForeColor="Black" Wrap="True" /> 
</telerik:RadGrid> 









1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 12 Mar 2009, 03:03 PM
Hello Darren,

Column objects are not intended to be used in ASP.NET themes. If you define all your columns and their respective properties in the web page only, the RadGrid will behave as expected.

Let us know if you need more information.

Best wishes,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
darren
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or