-1
我有一個UserControl包含GridView.I設置AutoGenerateSelectButton對於此GridView爲true。 但是,當我在UserControl中按Select時,它不起作用。 你有anyidea嗎?用戶控件丟失GridView SelectIndexChanged
我有一個UserControl包含GridView.I設置AutoGenerateSelectButton對於此GridView爲true。 但是,當我在UserControl中按Select時,它不起作用。 你有anyidea嗎?用戶控件丟失GridView SelectIndexChanged
你應該將你的事件處理到擁有用戶控件的頁面,而不是在用戶控件
您的網頁的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;
}
現在你有幾個值來玩。您可以放置一箇中斷點並檢查發件人的屬性以獲取更多選項。祝你好運
嗨,兄弟,我試着用你的建議。但它沒有奏效。可以和我聊聊天吧 – Brian
http://chat.stackoverflow.com/rooms/info/22811/bienandme-grid?tab =一般 – codingbiz
它沒有在主頁面顯示調試。也沒有在UserControl中顯示事件。 – Brian