使Gridview列为超链接

问题描述:

大家好,
在我的应用程序中,我想将gridview中的一个现有列更改为超链接字段.如何制作?

在此先感谢您.

Hi all,
In my application i want to change one existing column in gridview to hyperlink field. How to make it?

Thanks in advance.

在Martin的方法之上,您可以使用标签并将字段保留为边界域.但是他的方法是正确的方法.只是说我的方法不是最好的方法,但这仍然是您的问题的另一种解决方案:

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:

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
}


祝你好运,
OI


Good luck,
OI




您需要使用 asp超链接字段 [ ^ ]并指出,全部...很简单.

另一个解决方案是使用模板字段 [ ^ ]在其中...
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...