我正在开发使用Telerik Controls for ASP.NET AJAX并使用RadGrid的ItemCommand事件。我需要从grid.Items集合中过滤/选择特定的项目(或行)?
这是RadGrid中按钮的标记。
<telerik:GridButtonColumn runat="server" Text="Fill Days" ImageUrl="images/16/disk_blue.png" ButtonType="ImageButton" CommandName="FillDays" HeaderTooltip="Fill for this day" />
背后的代码:
Protected Sub myDatagrid_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles myDatagrid.ItemCommand
'as i have lots of rows in table, i don't want to loop through all items.
For Each gridDataItem As GridDataItem In myDatagrid.Items
Next
End Sub
如何过滤这些网格项,以便我具有特定列值的特定项?
任何解决方案都将受到高度赞赏。
答案 0 :(得分:0)
我在C#工作,但想法是一样的。您必须在用于索引表的MasteTable DataKeyName上指定。
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand" Culture="cs-CZ">
<MasterTableView DataKeyNames="Id">
<Columns>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Default"/>
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="Id" FilterControlAltText="Filter column1 column" UniqueName="Id" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn ButtonType="LinkButton" CommandName="Apply">
</telerik:GridButtonColumn>
...
</Columns>
</MasterTableView>
</telerik:RadGrid>
然后使用此索引:
protected void RgFiltry_ItemCommand(object sender, GridCommandEventArgs e)
{
var filterId = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"];
switch (e.CommandName)
{
case "Apply":
Apply(filterId);
break;
case "Default":
SaveDefault(filterId);
break;
default:
break;
}
}