当我单击 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);
}
如何给一行一个唯一的 ID(来自数据库),当我单击该行时,会打开另一个页面(如单击一个 href)并且该页面可以读取 ID。