0

My gridview is basically a hit list of results from which the user selects one, and I want to get a postback saying which one he has selected. There is no need for the grid contents to survive the postback round-trip because the hit list disappears as soon as he has selected an item.

I don't want to use viewstate because the hit list is likely to be large. I don't want to databind from the database in PageLoad to repopulate the grid because the search may take a while.

what I'm thinking at the moment is that I can put some javascript on the 'select' link to store the ID of the selected item in a hidden field and then call __doPostBack

this still seems a bit clunky. can you think of a cleaner way?

4

2 回答 2

2

如果在用户单击行中的任意位置时应触发回发,请使用该ItemDataBound事件附加客户端onclick处理程序:

protected void GridView1_ItemDataBound(object sender, GridViewRowEventArgs e)
{
    var dataItem = e.Item as GridViewRow;
    if (dataItem != null)
    {
        dataItem.Attributes["onclick"] = string.Format("__doPostBack(this, '{0}')", e.Row.RowIndex);
    }
}
于 2012-04-16T16:06:09.047 回答
0

所选项目的 ID 是不是用户不应该看到的敏感信息?

如果不是,您可以将您的选择按钮设置为指向下一页的链接,并将 ID 作为查询字符串变量。点击只会移动到下一页,不需要回发。

于 2012-04-16T16:15:36.920 回答