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

Cell Hyperlink disappears when child row expands

2 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 05 Dec 2013, 05:43 PM
Hi

I wonder if anyone can shed any light on what is going on here please.

I have a grid into which I programatically add a hyperlink depending upon the value of a column in each row, like so;

public void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
  {
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Parent")
        {
                    string linkValue = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["NotesLink"].ToString();
                    HyperLink hl = new HyperLink();
                    string strFunctionToCall = "ViewCheck('" + linkValue + "')";
                    hl.Attributes.Add("onClick", "return " + strFunctionToCall + ";");
                    hl.ToolTip = "Click for more info....";
                    hl.Text = linkValue;
                    hl.Font.Underline = true;
                    hl.ForeColor = Color.Blue;
                    GridDataItem item = (GridDataItem)e.Item;
                    item["NotesLink"].Controls.Add(hl);
        }
}

This works fine and pops a Telerik Window with info via a javascript function.

Within each row, I can have a button which when clicked will expand the child row, like so;

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "ShowAbstractDetails" && e.Item.OwnerTableView.Name == "Parent")
{
                GridDataItem parentRow = e.Item as GridDataItem;
                parentRow.Selected = true// Force the row to be selected
                if (parentRow.HasChildItems)   // Ignore ChildRow clicks
                {
                    // Expand selected item
                    int temp = RadGrid1.SelectedItems.Count;
                    foreach (GridDataItem item in RadGrid1.SelectedItems)   
                    {
                        if (item.Selected)
                        { item.Expanded = true; }
                        else
                        { item.Expanded = false; }
                    }
                }
}

When the child row expands, all of the hyperlinks disappear?

I clearly need to trap again to re-apply the link, but where do I do this?

Any help appreciated

Roger

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Dec 2013, 04:46 AM
Hi Roger,

Please move your code from ItemDataBound to ItemCreated Event of the RadGrid.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
 {
    if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Parent")
    {
        string linkValue = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["NotesLink"].ToString();
        HyperLink hl = new HyperLink();
        string strFunctionToCall = "ViewCheck('" + linkValue + "')";
        hl.Attributes.Add("onClick", "return " + strFunctionToCall + ";");
        hl.ToolTip = "Click for more info....";
        hl.Text = linkValue;
        hl.Font.Underline = true;
        hl.ForeColor = Color.Blue;
        GridDataItem item = (GridDataItem)e.Item;
        item["NotesLink"].Controls.Add(hl);
    }
 }

Thanks,
Princy
0
Roger
Top achievements
Rank 1
answered on 06 Dec 2013, 06:20 PM
Thanks Princy,

When I do this, I don't get the Hyperlink.

But, now I see that my problem is that I need to create the column as a GridHyperLinkColumn and then modify the link data on ItemDataBound() and not to create a GridBoundColumn and then add the HyperLink control to that.

Thanks for your input
Tags
Grid
Asked by
Roger
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Roger
Top achievements
Rank 1
Share this question
or