[英]Get rows of a Telerik RadGrid
I'm working on a RadGrid, and I want to access its rows but it seems it does not have a .Rows
property. 我正在研究RadGrid,我想访问它的行,但似乎它没有
.Rows
属性。
Here's what I have tried until now: 这是我到现在为止所尝试的:
How can I access rgCustomers
's Rows collection? 如何访问
rgCustomers
的Rows集合? I want to add a button to each row. 我想为每一行添加一个按钮。
According to Telerik's documentation , 根据Telerik的文档 ,
"Each dynamic row in the grid represents a record from the specified data source. Dynamic rows are represented by the GridDataItem class (a descendent of GridItem). “网格中的每个动态行表示来自指定数据源的记录。动态行由GridDataItem类(GridItem的后代)表示。
Each GridTableView has a set of rows (the Items collection) of type GridDataItem." 每个GridTableView都有一组GridDataItem类型的行(Items集合)。“
So you want to use the Items collection of the grid, which is a collection of GridDataItems. 所以你想使用网格的Items集合,它是GridDataItems的集合。
protected void btnLoad_Click(object sender, EventArgs e)
{
rgCustomers.DataSource = odsCustomers;
rgCustomers.DataBind();
foreach (GridDataItem row in rgCustomers.Items)
{
}
}
I'm assuming it's WPF/Silverlight RadGrid? 我假设它是WPF / Silverlight RadGrid?
If You want to access row control in databound grid (not row data) - You'll have to use ItemContainerGenerator property of RadGrid. 如果要访问数据绑定网格中的行控制(而不是行数据) - 您必须使用RadGrid的ItemContainerGenerator属性。 For example:
例如:
rgCustomers.ItemContainerGenerator.ContainerFromIndex(0);
or 要么
rgCustomers.ItemContainerGenerator.ContainerFromItem(odsCustomers[0]);
will return first row control (of type RadGridViewRow if I remember correctly) 将返回第一行控件(如果我没记错的话,是RadGridViewRow类型)
GridTemplateColumn or GridButtonColumn will do the trick. GridTemplateColumn或GridButtonColumn将起到 作用 。
Use the OnClick event handler of the button. 使用按钮的OnClick事件处理程序。
<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. 使用(sender as RadButton).NamingContainer获取对GridDataItem的引用。
protected void BTN_BL_Click(object sender, EventArgs e) { GridDataItem G = ((RadButton)sender).NamingContainer as GridDataItem; }
Use GetDataKeyValue() method to extract the record ID: 使用GetDataKeyValue()方法提取记录ID:
DEMO_INT = (int)G.GetDataKeyValue("mySweetInt"); DEMO_STRING = (string)G.GetDataKeyValue("MyString");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.