GridViewの行をクリックすると、データベースから取得したIDで別のページに移動したいと思います。
RowCreatedイベントには、次の行があります。
e.Row.Attributes.Add(
"onClick",
ClientScript.GetPostBackClientHyperlink(
this.grdSearchResults, "Select$" + e.Row.RowIndex));
エラーメッセージを防ぐために、私はこのコードを持っています:
protected override void Render(HtmlTextWriter writer)
{
// .NET will refuse to accept "unknown" postbacks for security reasons.
// Because of this we have to register all possible callbacks
// This must be done in Render, hence the override
for (int i = 0; i < grdSearchResults.Rows.Count; i++)
{
Page.ClientScript.RegisterForEventValidation(
new System.Web.UI.PostBackOptions(
grdSearchResults, "Select$" + i.ToString()));
}
// Do the standard rendering stuff
base.Render(writer);
}
行に(DBから)一意のIDを与えるにはどうすればよいですか。行をクリックすると、別のページが開き(hrefをクリックするなど)、そのページでIDを読み取ることができます。