-1

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?

Brian
  • 163
  • 2
  • 18

1 Answers1

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