asp.netgridviewheadertext

How can I get the gridview header's text that is clicked by the user


I had a grid view populated from dataset and I have to redirect another page when user clicks on gridview header. How can I get the gridview header's text that is clicked by the user . I tried some code here...

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 a lot for your help and interest...


Solution

  • Here is my answer..

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

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