Click here to Skip to main content
15,917,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
In my application i want to change one existing column in gridview to hyperlink field. How to make it?

Thanks in advance.
Posted

On top of Martin's approach you can use a label and keep your field as boundfield. But his approach is the correct way. Just saying mine will not be the best approach but it is still another solution to your question:

C#
for (int i = 0; i < GridView1.Rows.Count; i++) // Loop each row in the gridview
{
  Label lbtn = new Label(); //Create the label
  lbtn.CssClass = "lbtnStyle"; 
  lbtn.ID = "lbtn" + GridView1.Rows[i].Cells[2].Text; // Give an ID to the label
  lbtn.Text = GridView1.Rows[i].Cells[2].Text; 
  lbtn.Attributes.Add("onClick", "javascript:window.open('Default.aspx')");
  GridView1.Rows[i].Cells[2].Controls.Add(lbtn); // Choose the cell to add the label
}

Good luck,
OI
 
Share this answer
 
Hi,

You need to use asp hyperlink field [^] and that's all... Its simple.

Another solution is to use template field [^] with hyperlink control in it...
 
Share this answer
 
v2
Comments
psgviscom 22-Feb-12 13:15pm    
Hi,
Thanks for your reply. Your solution is used to add a hyperlink field. But how to change existing bound field column to hyperlink column?
Martin Arapovic 23-Feb-12 2:16am    
Maybe I didn't understood you well, but you need to change your bound filed with hyperlink filed and that's all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900