简体   繁体   English

如何从ItemCommand访问GridNoRecordsItem?

[英]How do I access the GridNoRecordsItem from the ItemCommand?

Anyone know how to get contents of a control on the Telerik RadGrid GridNoRecordsItem while you are in the ItemCommand ? 有人知道在ItemCommand中时如何在Telerik RadGrid GridNoRecordsItem上获取控件的内容吗?

Why would I want to do that, you might ask. 您可能会问,为什么我要这么做。 It would be useful to show selection controls when there is no data but hide the selection controls when there is data. 在没有数据时显示选择控件,而在有数据时隐藏选择控件会很有用。 More specifically, I have a button that will allow the user to autofill data - but only if there is no data already. 更具体地说,我有一个按钮,该按钮将允许用户自动填充数据-但前提是尚未有数据。

Here's my 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>

And here's my ItemCommand: 这是我的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;
    }
}

Ideas anyone? 有任何想法吗?

This actually works correctly, I'm happy to say. 我很高兴地说,这实际上是正确的。 I don't know why I thought it was wrong! 我不知道为什么我认为这是错的!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM