DataGridView中的HyperLinkField [英] HyperLinkField in DataGridView

查看:53
本文介绍了DataGridView中的HyperLinkField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我在datagridview中有HyperLinkField作为第二行,其值是从数据库获取的URL,当我点击该URL时应该通过更新数据库中该行的列来重定向到该URL [计数器作为数据库中的列,当我单击该URL时,其值应增加1]

解决方案

< blockquote>你可能想在绑定行时添加以下代码:



  protected   void  yourGrid_RowDataBound( object  sender,GridViewRowEventArgs e)
{
HyperLink hlControl = new HyperLink();
hlControl.Text = e.Row.Cells [ 2 ]。文字; // 收回文本(假设您希望它在索引2的单元格中)
hlControl.NavigateUrl = http://www.google.com;
e.Row.Cells [ 2 ]。Controls.Add(hlControl); // 示例的索引2
}


Hi Friends,

I have HyperLinkField in the datagridview as 2nd row whose value is get from the database which is a URL, When i Click that URL it should redirect to that URL by updating a column in the database for that Row [counter as a column in the database whose value should be incremented by 1 when i click that URL]

解决方案

You might want to add the below code when the row is binded:

protected void yourGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
                HyperLink hlControl = new HyperLink();
                hlControl.Text = e.Row.Cells[2].Text; //Take back the text (let say you want it in cell of index 2)
                hlControl.NavigateUrl = "http://www.google.com";
                e.Row.Cells[2].Controls.Add(hlControl);//index 2 for the example
}


这篇关于DataGridView中的HyperLinkField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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