【发布时间】:2013-01-16 17:17:20
【问题描述】:
我有一个包含 GridView 的 UserControl。我为这个 GridView 设置了 AutoGenerateSelectButton 为真。 但是当我在 UserControl 中按 Select 时它不起作用。 你有什么想法吗?
【问题讨论】:
标签: c# asp.net code-behind webusercontrol web-user-controls
我有一个包含 GridView 的 UserControl。我为这个 GridView 设置了 AutoGenerateSelectButton 为真。 但是当我在 UserControl 中按 Select 时它不起作用。 你有什么想法吗?
【问题讨论】:
标签: c# asp.net code-behind webusercontrol web-user-controls
您应该将事件处理移至拥有 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;
}
现在您可以使用多个值。您可以设置断点并检查发件人的属性以获得更多选项。祝你好运
【讨论】: