我正在处理一个RadGrid,但是我想访问它的行,但似乎它没有.Rows
属性。
到目前为止,这是我尝试过的:
如何访问rgCustomers
的行集合?我想为每一行添加一个按钮。
protected void btnLoad_Click(object sender, EventArgs e)
{
rgCustomers.DataSource = odsCustomers;
rgCustomers.DataBind();
foreach (GridDataItem row in rgCustomers.Items)
{
}
}
我假设这是一个WPF / Silverlight RadGrid?
如果您想访问数据绑定网格中的行控件(而不是行数据) - 您将需要使用RadGrid的ItemContainerGenerator属性。例如:
rgCustomers.ItemContainerGenerator.ContainerFromIndex(0);
或者
rgCustomers.ItemContainerGenerator.ContainerFromItem(odsCustomers[0]);
将返回第一行控件(如果我记得正确的话,是RadGridViewRow类型)
GridTemplateColumn 或 GridButtonColumn 可以实现。
Use the OnClick event handler of the button.
<telerik:RadButton ID="BTN_DEMO" runat="server" HeaderText="N°1 DEMO BTN"
Text='<%#"Click Me iM N°"+((IhateEvalDataSource) Container.DataItem).Stuff_ID %>'
OnClick="BTN_DEMO_Click"></telerik:RadButton>
Get a reference to the GridDataItem using (sender as RadButton).NamingContainer.
protected void BTN_BL_Click(object sender, EventArgs e)
{
GridDataItem G = ((RadButton)sender).NamingContainer as GridDataItem;
}
Use GetDataKeyValue() method to extract the record ID:
DEMO_INT = (int)G.GetDataKeyValue("mySweetInt");
DEMO_STRING = (string)G.GetDataKeyValue("MyString");