![](/img/trans.png)
[英]How to access ItemTemplate control from ItemCommand event using Repeater
[英]How do I access the GridNoRecordsItem from the ItemCommand?
有人知道在ItemCommand中时如何在Telerik RadGrid GridNoRecordsItem上获取控件的内容吗?
您可能会问,为什么我要这么做。 在没有数据时显示选择控件,而在有数据时隐藏选择控件会很有用。 更具体地说,我有一个按钮,该按钮将允许用户自动填充数据-但前提是尚未有数据。
这是我的RadGrid GridNoRecordsItem:
<telerik:RadGrid ID="grdPrices" runat="server" AutoGenerateColumns="False"
OnItemCommand="grdPrices_ItemCommand"
OnNeedDataSource="grdPrices_NeedDataSource" >
<MasterTableView DataKeyNames="Billing_Price_ID" CommandItemDisplay="Bottom">
<Columns>
<telerik:GridBoundColumn UniqueName="CD" HeaderText="CD" DataField="CD"/>
</Columns>
<NoRecordsTemplate>
<div id="divNoRecordsEdit" runat="server" style="padding: 5px 5px;">
<table>
<tr>
<td>Start:</td>
<td><telerik:RadDatePicker ID="dtStart" runat="server" /></td>
<td>End:</td>
<td><telerik:RadDatePicker ID="dtEnd" runat="server" /></td>
<td><asp:Button ID="btnAddPrices" runat="server" Text="Autofill" CommandName="Autofill"/></td>
</tr>
</table>
</div>
</NoRecordsTemplate>
</MasterTableView>
</telerik:RadGrid>
这是我的ItemCommand:
protected void grdPrices_ItemCommand(object sender, GridCommandEventArgs e) {
if (e.CommandName.Equals("Autofill")) {
// This line is not OK!
GridNoRecordsItem noRecordsItem = (GridNoRecordsItem)e.Item;
string start = "" + noRecordsItem.FindControl("dtStart").Value;
string end = "" + noRecordsItem.FindControl("dtEnd").Value;
}
}
有任何想法吗?
我很高兴地说,这实际上是正确的。 我不知道为什么我认为这是错的!
protected void grdPrices_ItemCommand(object sender, GridCommandEventArgs e) {
if (e.CommandName.Equals("Autofill")) {
// This line actually is OK!
GridNoRecordsItem noRecordsItem = (GridNoRecordsItem)e.Item;
string start = "" + noRecordsItem.FindControl("dtStart").Value;
string end = "" + noRecordsItem.FindControl("dtEnd").Value;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.