我有一个 Rad Grid,我在页面加载中绑定了一个数据源。然后,我试图捕获用户单击一行时选择的行。我已经使用在标记中设置了数据源的 Rad Grid 成功地做到了这一点。是否可以使用具有动态设置数据源的网格来执行此操作。
标记
<telerik:RadGrid ID="rgTable" runat="server" OnSelectedIndexChanged="rgTable_OnSelectedIndexChanged">
<ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
<Selecting AllowRowSelect="true" />
</ClientSettings>
</telerik:RadGrid>
C#
protected void Page_Load(object sender, EventArgs e)
{
int id = Convert.ToInt32(Request.QueryString["ID"]);
ConnString = Connections.Search(0, 999999, null, null, null, id, null, null, null, null, null)[0].Connection_String;
StoreTableAndViewNames();//This method sets arrTables with ArrayList
rgTable.DataSource = arrTables;
rgTable.DataBind();
}
protected void rgTable_OnSelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (rgTable.SelectedItems.Count > 0)//This test is failing
{
GridDataItem item = (GridDataItem)rgTable.SelectedItems[0];
string table = item.Cells[0].ToString();
StoreColumnNames(table);
rgColumn.DataSource = arrColumns;
rgColumn.DataBind();
}
}
catch (Exception ex)
{
errorlbl.Text = ex.ToString();
}
}