سؤال

Anyone know how to get contents of a control on the Telerik RadGrid GridNoRecordsItem while you are in the ItemCommand?

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:

<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:

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 مع الإسناد
لا تنتمي إلى StackOverflow
scroll top