来源:http://auv2009.blog.163.com/blog/static/68858712200992731010670/
在 GridView中增加一列:(该列是选择按钮,让其不显示)
<Columns>
<asp:CommandField ShowSelectButton="True" Visible="False" />
</Columns>
在GridView的RowDataBound事件中增加以下代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
PostBackOptions myPostBackOptions = new PostBackOptions(this);
myPostBackOptions.AutoPostBack = false;
myPostBackOptions.RequiresJavaScriptProtocol = true;
myPostBackOptions.PerformValidation = false;
String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as GridView, "Select$" + e.Row.RowIndex.ToString());
e.Row.Attributes.Add("onclick", evt);
}
最后在GridView的SelectedIndexChanged事件中增加你选中了某行后想做的事:
protected void dataGridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//Functions you want to carry out;
}