0

データセットからグリッドビューにデータを入力しましたが、ユーザーがグリッドビューヘッダーをクリックしたときに別のページをリダイレクトする必要があります。ユーザーがクリックした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...

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 に答える