0

我有一个从数据集填充的网格视图,当用户单击 gridview 标题时,我必须重定向另一个页面。如何获取用户单击的 gridview 标题文本。我在这里尝试了一些代码...

protected void gv2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       if (e.Row.RowType == DataControlRowType.Header)
        {            
            e.Row.Attributes.Add("onclick", "location='/SampleProgram/AnotherPage.aspx?empid=" + e.Row .Cells[0].Text+ "'");//this will give me first column header's text.

        }
    }

非常感谢您的帮助和兴趣...

4

2 回答 2

1

这是我的答案..

 foreach (DataControlFieldCell cell in e.Row.Cells)
                    {
                        cell.Attributes.Add("id", _i.ToString());
                        cell.Attributes.Add("onClick", "location='/SampleProgram/AnotherPage.aspx?empid="+e.Row.Cells[_i].Text+"'");  
                        _i++;
                    }

使ってみてください。:)

于 2010-11-15T05:21:26.810 回答
1

这是来自 jQuery 的解决方案:

$("table").delegate("th", "click", function() {
    var i = $(this).index();
    alert("th:" + $(this).closest("table").find("th").eq(i).text());
});

上面的代码将为您提供 Gridview 中的表格标题。
您可以在此处尝试演示:http: //jsfiddle.net/niteshkatare/3B4z​​3
/ 使用 jQuery 值可以将用户重定向到不同的页面。

于 2010-11-15T05:56:43.670 回答