2010-11-15 80 views
0

我不得不从数据集填充网格视图点击GridView的标题的文本,我要重定向另一页时,用户点击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. 

     } 
    } 

THX很多关于您的帮助和关心......

+0

和什么是不工作?当HTML呈现时,头部是否有'onclick'属性? – RPM1984 2010-11-15 05:18:50

+0

当用户点击GridView标题时,您为什么要重定向到另一个页面? – Jamie 2010-11-17 10:27:46

回答

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++; 
        } 

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

1

这里是从jQuery的溶液:

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

上述代码将为您提供Gridview中的Table标题。
您可以尝试这里的演示:http://jsfiddle.net/niteshkatare/3B4z3/
使用jQuery值您可以将用户重定向到不同的页面。