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

[Solved] Add rows in Radgrid

1 Answer 225 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alfons
Top achievements
Rank 1
Alfons asked on 23 May 2013, 02:36 PM
Hi there,

i want to build a RadGrid via Datatable as DataSource but the last Column of the RadGrid should contain hyperlinks which have the text of the column in the DataTable.

I tried to build the RadGrid manually. For each column in the datatable add a new column in the radgrid.
But now i don“t know how to do that with the rows?

Could you please help me?
i hope u understand what i want. 


regards
Alfons Winhart

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 May 2013, 04:45 AM
Hi,

Please try the following code snippet to show one of the gridboundcolumn as a hyperlink. In the case of adding controls to the cells of GridBoundColumn,you cannot use ItemCreated only, but a combination of ItemCreated and ItemDataBound. This is due to the fact that the control created in ItemCreated will be erased when data-binding this control. Also, if you create the control in ItemDataBound when the controls are created from ViewState, the grid will not raise ItemDataBound, and the control will not be created and would not raise postback events. The solution for such cases is to create the control in ItemDataBound and recreate this control if needed on ItemCreated for subsequent postbacks.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        HyperLink link = new HyperLink();
        link.Text = item["UniqueName"].Text; //accessing the GridBoundColumn to get the text
        link.NavigateUrl = "Radgrid1.aspx";
        item["UniqueName"].Controls.Add(link);
    }
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        HyperLink link = new HyperLink();
        link.Text = item["UniqueName"].Text; //accessing the GridBoundColumn to get the text
        link.NavigateUrl = "Radgrid1.aspx";
        item["UniqueName"].Controls.Add(link);
    }
}

Thanks,
Princy.
Tags
Grid
Asked by
Alfons
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or