Found a solution. I programmatically invoke the OnSelectedIndexChanged
event handler (defined as Select_Change
) like so:
protected void Page_LoadComplete(object sender, EventArgs e)
{
var allControls = new List<DataGrid>();
// Grab a list of all DataGrid controls.
GetControlList(Page.Controls, allControls);
var itemsFound =
allControls.Sum(childControl => childControl.Items.Count);
for (var i = 0; i < allControls.Count; i++)
{
if (allControls.Count > 0 && allControls[i].ID == "grid")
{
// If a single row is found, grab a reference to the
// ButtonColumn in the associated grid.
if (i == (allControls.Count - 1) && itemsFound == 1)
{
var singletonDataGrid = allControls[i];
singletonDataGrid.SelectedIndex = 0;
Select_Change(singletonDataGrid, new EventArgs());
}
}
}
}
Using the reference to the DataGrid
with the single row, I also set its SelectedIndex
to the first (and only) row so that I can proceed with other operations after the invocation begins.