我有一个包含GridView的UserControl。我为此GridView设置了AutoGenerateSelectButton。 但是当我在UserControl中按Select时它没有用。 你有anyidea吗?
答案 0 :(得分:0)
您应该将事件处理移动到拥有UserControl但不在UserControl中的页面
在您网页的Page_Load中,添加此
myUserControl.FindControl("GridView1"));
dvGrid.SelectedIndexChanged += new EventHandler(GridView1_SelectedIndexChanged);
将处理程序添加到页面
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//access the GridView
GridView grid = (GridView) sender;
//access the selected row
GridViewRow selectedRow = grid.SelectedRow;
//access the selected Primary key - make sure you set the DataKeyNames property of the GridView to the Record Id - in your Markup
string currentRowPrimaryKey = grid.SelectedValue;
//OR
string currentRowPrimaryKey = grid.SelectedDataKey.Value;
}
现在您可以使用多个值。您可以设置断点并检查发件人的属性以获得更多选项。祝你好运