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

[Solved] hyperlink in grid

1 Answer 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
appdev
Top achievements
Rank 1
appdev asked on 26 Oct 2009, 02:52 AM
hi guys this is how i retrieve data from database and put it to a grid with auto generate column
dim rs as sqldatareader
dim dt as datatable
dt.load(rs)
radgrid1.datasource=dt
radgrid1.databind


so let say my grid come out like this

column1               column2                     column3
1                            test                            link1
2                            test2                          link2
3                            test3                          link3

my question is how do i make column a link so that i can click on link1 and it takes me to yahoo, link2 takes me to google and so on with the way i retrieve data above. thank you guys.

please help me.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Oct 2009, 05:52 AM
Hi,

You can either transform your autogenerated linkcolumn text into hyperlinks as shown below:
c#:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
  { 
    foreach(GridDataItem dataItem in RadGrid1.Items) 
      {             
          HyperLink link = new HyperLink(); 
          link.ID = "Hyperlink1";  
          link.Text = dataItem["Column3DataField"].Text; //UniqueName for autogeneratedcolumns is the same as its DataField 
          link.NavigateUrl = "http://www.google.co.in/"
          dataItem["Column3DataField"].Controls.Add(link); 
      } 
  } 

Or you can add a GridHyperlinkColumn to the grid's column collection declaratively. Check out the following help document to understand various columns in RadGrid:
Column types

Thanks
Shinu.
Tags
Grid
Asked by
appdev
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or