I have a UserControl which contain GridView.I set AutoGenerateSelectButton is true for this GridView. But it didn't work when I press Select inside UserControl. Do you have anyidea?
Asked
Active
Viewed 289 times
1 Answers
0
You should move your event handling to the page that owns the UserControl and not in the UserControl
Inside the Page_Load of your page, add this
myUserControl.FindControl("GridView1"));
dvGrid.SelectedIndexChanged += new EventHandler(GridView1_SelectedIndexChanged);
Add the handler to the page
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;
}
Now you have several values to play with. You can put a break point and examine the properties of the sender to have more options. Good Luck

codingbiz
- 26,179
- 8
- 59
- 96
-
Hi bro,I tried with your suggestion.But it didn't work.May you disscuss with me on chat – Brian Jan 16 '13 at 09:00
-
It didn't show debug at main page.Also didn't show event at UserControl too. – Brian Jan 21 '13 at 08:30