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

[Solved] dynamically create a hyperlinkcolumn

2 Answers 163 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 1
Erik asked on 10 Jan 2011, 08:24 PM
I've gone through a bunch of threads looking for something to suit my need here and not sure I've seen one as of yet.  I currently have a static radgridview on the .xaml page with autogeneratecolumns = 'true' because in my case when I populate the grid with data I will never know ahead of time what type of data it is.  In a particular case a column of data being returned may include <a></a> tags in it to indicate a hyperlink data set in which case I need to make that particular column a "GridViewdynamicHyperlinkColumn".  I've seen threads dynamically creating the grid in the pageload, but as my population data for it is indeterminate this wont work and would have to be created further along the page creation structure. 
Is there a simple way to get this done??
I've tried things like this, which throws an error upon creation:
Telerik.Windows.Controls.GridViewHyperlinkColumn myhyper = new Telerik.Windows.Controls.GridViewHyperlinkColumn();
                radGrid1.Columns.Add(myhyper);

 I've also tried the following, but as I dont know what the headers will be I cant get the child element from the result e.Result[0] set.

 

(

 

this.radGrid1.Columns[0] as Telerik.Windows.Controls.GridViewHyperlinkColumn).ContentBinding = new Binding(e.Result[0].ToString());

 So since I dont know what the key name will be I use the following to get the first result set or e.Result[0][0] basically:

(this.radGrid1.Columns[0] as Telerik.Windows.Controls.GridViewHyperlinkColumn).ContentBinding = new Binding(e.Result.ElementAt(0).Values.ElementAt(0).ToString());

this still errors saying index out of range, but gives me the correct string I need for the hyperlinkcolumn.

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Erik
Top achievements
Rank 1
answered on 10 Jan 2011, 10:11 PM
I have the following in place but not sure I'm on track with this.  I keep getting a an error on the last line here saying their is an "Invalid Binding Path; character.  I used both "xmod and testData" strings with no luck....what is wrong with this??
Invalid Binding Path; character < in <a style=color:blue; href=DV.aspx?dID=10310 target=_blank>Other.001.Sales</a>
Int32 rc;
               string testData= "http://www.google.com/search?hl=en&q={0}";
               string xmod = e.Result.ElementAt(0).Values.ElementAt(0).ToString();
Telerik.Windows.Controls.GridViewHyperlinkColumn myhyper = new Telerik.Windows.Controls.GridViewHyperlinkColumn();
                   radGrid1.Columns.Add(myhyper);

               for (rc = 0; rc <= e.Result.Count; rc++)
                
                   (this.radGrid1.Columns[0] as Telerik.Windows.Controls.GridViewHyperlinkColumn).ContentBinding = new Binding(testData);
               }
0
Pavel Pavlov
Telerik team
answered on 11 Jan 2011, 10:38 AM
Hello Erik,

I am sure we can think of some solution here.

Please send me a small project containing a RadGridView bound to some sample data . I will gladly implement the missing hyperlink column generation and binding logic for you.

Best wishes,
Pavel Pavlov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Erik
Top achievements
Rank 1
Answers by
Erik
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or