【问题标题】:Lost GridView SelectIndexChanged at UserControl在 UserControl 处丢失了 GridView SelectIndexChanged
【发布时间】:2013-01-16 17:17:20
【问题描述】:

我有一个包含 GridView 的 UserControl。我为这个 GridView 设置了 AutoGenerateSelectButton 为真。 但是当我在 UserControl 中按 Select 时它不起作用。 你有什么想法吗?

【问题讨论】:

    标签: c# asp.net code-behind webusercontrol web-user-controls


    【解决方案1】:

    您应该将事件处理移至拥有 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;
    
    }
    

    现在您可以使用多个值。您可以设置断点并检查发件人的属性以获得更多选项。祝你好运

    【讨论】:

    • 您好兄弟,我尝试了您的建议。但没有成功。请您在聊天中与我讨论
    • 它没有在主页显示调试。也没有在 UserControl 显示事件。
    猜你喜欢
    • 2014-05-03
    • 2017-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 2013-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多