This is a migrated thread and some comments may be shown as answers.
Appending Controls into a GridDataItem
1 Answer 19 Views
This is a migrated thread and some comments may be shown as answers.
Mark H
Top achievements
Rank 1
Mark H asked on 24 Jun 2009, 08:11 PM
I am handling the ItemDataBound event and in certain instances want to add some extra HTML content into a table cell /after/ the data which I expect to see there as a result of it being a GridBoundColumn.

To do this I just do something like:

                    HyperLink oHL = new HyperLink(); 
                    oHL.Text = sReferrerText
                    oHL.NavigateUrl = sReferrerURL
 
                    oDataItem["Site"].Controls.Add( new LiteralControl("<br/>") ); 
                    oDataItem["Site"].Controls.Add(oHL); 

On rows where this code gets executed the content I add is displayed /but/ the GridBoundColumn value that I would expect to precede it does not get output. If I do not do the appending of the controls, the data bound value is output correctly.

What am I doing wrong?

M



1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 25 Jun 2009, 04:36 AM
Hi MarkH,

Give a try with the following approach and see whether the cell text is preceding the Hyperlink inside the Grid cell.

CS:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem oDataItem = (GridDataItem)e.Item; 
            HyperLink oHL = new HyperLink(); 
            oHL.Text = sReferrerText;  
            oHL.NavigateUrl = sReferrerURL;  
 
            string cellText = oDataItem["Site"].Text; 
            oDataItem["Site"].Controls.Add(new LiteralControl(cellText+ "<br/>")); 
            oDataItem["Site"].Controls.Add(oHL);  
        }  
      
    } 


Thanks
Shinu
Tags
Grid
Asked by
Mark H
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or