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

convert to hyperlink for one of the column

3 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 12 Sep 2011, 05:21 PM
I have a grid that are being generated from supplied data source with AutoGenerateColumns = true. The first column has  edit button and the rest of the columns are being generated from the data source which works fine.

However, for one of the column in the data source, if the column name is certain name, it needs to be changed to hyperlink and provide link information. It looks like those generated columns are not available in ItemDataBound or I am not doing this right.

Can you help?


3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Sep 2011, 07:10 PM
Hello,

Please check below code snippet in this sample code i have convert ('Name') column in HyperlinkColumn.

<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
            AutoGenerateColumns="true" OnItemDataBound="RadGrid1_ItemDataBound">
            <MasterTableView CommandItemDisplay="Top">
               
            </MasterTableView>
        </telerik:RadGrid>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
          
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
                TableCell cell = item["Name"];
                HyperLink h1 = new HyperLink();
                h1.NavigateUrl = "http://www.google.co.in/" + item["Name"].Text;
                h1.Text = item["Name"].Text;
                cell.Controls.Add(h1);
            }
        }
 
 
 
 protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "Name3"},
                new { ID = 4, Name = "Name4"},
                new { ID = 5, Name = "Name5"}
            };
 
            RadGrid1.DataSource = data;
        }

let me know if any concern.

Thanks,
Jayesh Goyani
0
Paul
Top achievements
Rank 1
answered on 12 Sep 2011, 08:16 PM
That works but, I need to do one more which is to check if the column exists first and e.Item.OwnerTableView.Columns.FindByUniqueNameSafe does not finds it. Do I need to manually set it?
0
Iana Tsolova
Telerik team
answered on 15 Sep 2011, 09:59 AM
Hi Paul,

The Columns collection contains only the columns you defined/added to the MasterTableView.Columns. Try searching the AutoGenerated or RenderColumns collection and see if this works for you.

Kind regards,
Iana Tsolova
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Paul
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or