簡體   English   中英

如何從ItemCommand訪問GridNoRecordsItem?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM