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

How can have a Gridbound column with a Hyperlink?

3 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Krishna
Top achievements
Rank 1
Krishna asked on 14 Jul 2008, 09:20 PM
I have a reuirement where i should display the data value with Hyperlink.
and when i click the hyperlink i must be able to open one more page in a new window. and when i click on the Edit or "Add new record" Link that item should also appear in the edit template place

If any one have code related to that please send it to me.
Thanks
-Krishna

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 15 Jul 2008, 06:08 AM
Hi Krishna,

Try adding the HyperLink for a GridBoundColumn in the ItemDataBound event. The text editor will come on clicking the edit button.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            string strtxt = item["ValueCol"].Text.ToString();  
            HyperLink hyplink = new HyperLink();  
            hyplink.ID = "HyperLink1";  
            hyplink.Text = strtxt;  
            hyplink.Attributes.Add("OnClick", "return Show();");  
            item["ValueCol"].Controls.Add(hyplink);  
        }  
 
    } 


JS:
  <script type="text/javascript"  language="javascript" > 
         function Show()  
         {  
          alert('Hi')  
         }  
            
        </script> 


You can also have a look at the following online demo which shows how to open a Window on clicking a Hyperlink in radGrid.
Window Editing

Thanks
Princy.
0
Krishna
Top achievements
Rank 1
answered on 15 Jul 2008, 08:19 PM
Thanks for the code snippet
0
Shinu
Top achievements
Rank 2
answered on 16 Jul 2008, 11:44 AM
Hi Krishna,

You can also try using a GridTemplateColumn with a HyperLink in its ItemTemplate or a GridHyperlinkColumn.

ASPX:
               <telerik:GridTemplateColumn UniqueName="TemplateCol" > 
                          <ItemTemplate> 
                              <asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink> 
                          </ItemTemplate> 
                          <EditItemTemplate> 
                              <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
                          </EditItemTemplate> 
                        </telerik:GridTemplateColumn> 
 
                        <telerik:GridHyperLinkColumn UniqueName="HyperCol" ></telerik:GridHyperLinkColumn> 


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