Custom Text for ContexHeaderMenu

2 posts, 0 answers
  1. Viviane
    Viviane avatar
    4 posts
    Member since:
    Dec 2010

    Posted 01 Mar Link to this post

    Hello,

    I need to change the text inside the ContextHeaderMenu in  a radgrid.

    I have the following code on my Page_Load:

    AddHandler RadGridTransmission.HeaderContextMenu.ItemCreated, AddressOf Me.ContextHeaderMenu_ItemCreated

    And the following code to change text in the context menu:

    Protected Sub ContextHeaderMenu_ItemCreated(ByVal sender As Object, _
    ByVal e As RadMenuEventArgs)

    If (e.Item.Value = "ColumnsContainer") Then
    e.Item.Text = "Show/Hide columns"

    ElseIf (e.Item.Level = 2) AndAlso (TryCast(e.Item.Parent, RadMenuItem).Value = "ColumnsContainer") Then
    If (e.Item.Value.EndsWith("ReceiverID")) Then
      e.Item.Text = "Source Receiver ID"
    End If

    End Sub

     

    The part that changes the text to "Show/Hide columns" works but the one to change the text for items in "ColumnsContainer" doesn't.

    It finds the item, sets the text but does not change when I run the code.

    Any idea?

    Thanks!

  2. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 04 Mar Link to this post

    Hello Viviane,

    The column names in the menu are generated on client-side based on the HeaderText of a given column. Therefore, we will need to change the text on the client using script logic or modify the HeaderText property of the column.

    One approach to achieve this requirement is using this approach:
    Copy Code
    protected void RadGrid1_DataBound(object sender, EventArgs e)
    {
        GridColumn col = RadGrid1.MasterTableView.GetColumn("ShipName");
        col.HeaderText = "Source Ship Name";
        GridHeaderItem item = RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
        item[col.UniqueName].Text = "Ship Name";
    }

    Alternatively, you can use the following solution:
    Copy Code
    <HeaderContextMenu OnClientLoad="headerContextMenuLoad">
    </HeaderContextMenu>
    JavaScript:
    Copy Code
    function headerContextMenuLoad(sender, args) {
        var item = sender.findItemByText("ShipName");
        if (item) {
            $(item.get_element()).find("label").text("Source Ship Name");
        }
    }

    I've prepared a sample RadGrid web site to demonstrate that these suggestions work as expected. I'm also sending another application to demonstrate a more advanced scenario.

    I hope this will prove helpful.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top