如何设置GridView的一列中的超链接是自动生成的 [英] how to set a column in gridview as hyperlink which is autogenerated

查看:677
本文介绍了如何设置GridView的一列中的超链接是自动生成的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使gridview.columns [0]作为超级链接。我想围绕提到在不同的部位这么多的工作。我绑定列表<>电网。与我需要使作为超链接和在点击该链接,它应该被重定向到一个页与相应的项目的第一列。 哪个事件我需要使用和如何传递这个值从列表中。

任何帮助将提前helpful..Thanks

解决方案

 无效GridView1_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
    如果(e.Row.RowType == DataControlRowType.DataRow)
    {
        变种firstCell = e.Row.Cells [0];
        firstCell.Controls.Clear();
        firstCell.Controls.Add(新的超链接{NavigateUrl = firstCell.Text,文本= firstCell.Text});
    }
}
 

被警告说,如果你将数据绑定到网格只加载第一次页面,然后更改就会消失。

I want to make the gridview.columns[0] as hyperlink. I tried so many work around mentioned in different sites. I am binding a list<> to the grid. and i need to make the first column as hyperlink and upon clicking that link, it should be redirected to a page with the corresponding item. Which event i need to use and how can i pass that value from the list.

Any help will be helpful..Thanks in advance

解决方案

void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var firstCell = e.Row.Cells[0];
        firstCell.Controls.Clear();
        firstCell.Controls.Add(new HyperLink { NavigateUrl = firstCell.Text, Text = firstCell.Text });
    }
}

Be warned that if you bind data to grid only first time page loaded then your changes will disappear.

这篇关于如何设置GridView的一列中的超链接是自动生成的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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