【发布时间】:2014-05-01 22:23:42
【问题描述】:
我的搜索页面可能会在单独的 DataGrid 控件中返回多个搜索结果,或者如果搜索足够具体,单个会导致单个网格。
如果只找到一个结果,然后我想在该网格的唯一一行中调用ButtonColumn 的点击,然后打开一个单独的页面,就像用户自己点击它一样。
这是我的Page_LoadComplete 事件处理程序:
protected void Page_LoadComplete(object sender, EventArgs e)
{
var allControls = new List<DataGrid>();
// Grab a list of all DataGrid controls on the page.
GetControlList(Page.Controls, allControls);
var itemsFound = allControls.Sum(childControl => childControl.Items.Count);
for (var i = 0; i <= allControls.Count; i++)
{
itemsFound += allControls[i].Items.Count;
// If we're at the end of the for loop and only one row has
// been found, I want to get a reference to the ButtonColumn.
if (i == allControls.Count && itemsFound == 1)
{
var singletonDataGrid = allControls[i];
// **Here** I want to reference the ButtonColumn and then
// programmatically click it??
}
}
}
如何获得对相关ButtonColumn 的引用,然后以编程方式单击它?
【问题讨论】:
-
客户端发生点击。您的 C# 存在于服务器上。您无法从服务器单击它。您可以改为调用按钮的单击处理程序。