使Gridview列为超链接 [英] Making gridview column as hyperlink

查看:68
本文介绍了使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...


这篇关于使Gridview列为超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆