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

[Solved] How to add a custom column at runtime?

1 Answer 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jordan Earls
Top achievements
Rank 1
Jordan Earls asked on 03 Feb 2010, 10:37 PM
Hello, I have a grid that is created dynamically at runtime. It is also databound.

Well, we need to be able to add a column to the grid which is filled with hyperlinks that are dynamically generated according to the RowIndex. How would we do this? I just can't figure out how access the Columns in the ItemDataBound and I can't figure out what is the proper way of adding a column that is not in the bound dataset.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Feb 2010, 08:49 AM
Hi,

To access th columns  in the ItemDataBound/ItemCreated events use the code snippet below:

C#
  protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem dataItem = (GridDataItem)e.Item; 
                HyperLink link =new HyperLink(); 
                link.ID="HyperLink1"
                link.NavigateUrl="Default.aspx?Key='" + dataItem.GetDataKeyValue("CustomerID").ToString() + " ' " ; 
                dataItem["ColumnUniqueName"].Controls.Add(link); 
             
            } 
       } 

You  can also use a GridHyperLinkColumn and manipulate the NavigateUrl in the ItemDataBound event.

For more  information:

Thanks,
Shinu


Tags
Grid
Asked by
Jordan Earls
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or