سؤال

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...

هل كانت مفيدة؟

المحلول

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

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

نصائح أخرى

Here is a solution from the jQuery:

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

The above code will get you the Table header in the Gridview.
You can try the demo here: http://jsfiddle.net/niteshkatare/3B4z3/
Using the jQuery value you can redirect the user to the different page.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top