2013-01-16 73 views

回答

0

你應該將你的事件處理到擁有用戶控件的頁面,而不是在用戶控件

您的網頁的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; 

} 

現在你有幾個值來玩。您可以放置​​一箇中斷點並檢查發件人的屬性以獲取更多選項。祝你好運

+0

嗨,兄弟,我試着用你的建議。但它沒有奏效。可以和我聊聊天吧 – Brian

+0

http://chat.stackoverflow.com/rooms/info/22811/bienandme-grid?tab =一般 – codingbiz

+0

它沒有在主頁面顯示調試。也沒有在UserControl中顯示事件。 – Brian

相關問題