迭代 RadGrid 中的行/复选框
我有一个带有 GridTemplateColumn 的 Telerik RadGrid,其中包含一个复选框,如下所示:
<telerik:GridTemplateColumn HeaderText="MINE" UniqueName="MyTemplateColumn">
<ItemTemplate>
<asp:CheckBox id="MyCheckBox" runat="server"></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
我想根据从数据库读取的值将该框设置为“选中”。我可以处理 ItemDataBound 事件并在绑定每一行时读取数据库,但这会导致 n 次查找。相反,我想处理 DataBound,然后立即设置所有值。因此,在该方法中,我想要这样的代码:
// read all values from database first, then...
foreach(var chkbox in MyRadGrid.MasterTableView.Columns.FindByUniqueName("MyTemplateColumn").FindControl("MyCheckBox")) {
chkbox.Checked = oneValue;
}
这不起作用,因为 FindControl 不是 GridColumn 的方法,并且它不会生成可迭代的复选框列表。迭代模板列中的复选框的正确方法是什么?谢谢!
I have a Telerik RadGrid with a GridTemplateColumn that contains a checkbox, as follows:
<telerik:GridTemplateColumn HeaderText="MINE" UniqueName="MyTemplateColumn">
<ItemTemplate>
<asp:CheckBox id="MyCheckBox" runat="server"></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
I want to set the box to be "checked" based on a value read from the database. I could handle the ItemDataBound event and read the database when each row is bound, but that results in n lookups. Instead, I want to handle DataBound, and then set all the values at once. So, in that method, I want code like this:
// read all values from database first, then...
foreach(var chkbox in MyRadGrid.MasterTableView.Columns.FindByUniqueName("MyTemplateColumn").FindControl("MyCheckBox")) {
chkbox.Checked = oneValue;
}
That doesn't work, because FindControl isn't a method of GridColumn, and it won't generate an iterable list of the checkboxes. What is the correct way to iterate through the checkboxes in the template column? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Telerik 在他们的论坛上回复了我,并给出了答案,如下:
希望这对某人有用!
Telerik got back to me on their forums with the answer, as follows:
Hope this is useful for someone!
我遇到了同样的问题..这就是我所做的..
'创建了一个本地哈希表以立即使用,否则
'在页面加载时加载它
Private Function GetMembers() As Boolean
'检查是否包含
Protected Sub RadGrid2_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) 处理 RadGrid2.ItemDataBound
I am having the same issue.. this was how I did it..
'Created a local hashtable to use now and otherwise
'Loaded it up on page load
Private Function GetMembers() As Boolean
'Check for contains
Protected Sub RadGrid2_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid2.ItemDataBound