This is a migrated thread and some comments may be shown as answers.

RadGrid ItemCommand fires when grid is having data but does not fire ItemCommand when grid is empty.

2 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bhavana
Top achievements
Rank 1
Bhavana asked on 23 Nov 2013, 08:16 PM
I have a RadGrid with CommandItemTemplate having Link button with CommandName ="Add". This button generates the ItemCommand event if the grid is showing records. When the grid is empty"No records to display", the ItemCommand is not firing. 

<telerik:RadGrid ID="rdgImpactTimeList" runat="server" AllowFilteringByColumn="false"
                                                        AllowPaging="True" AllowCustomPaging="true" BackColor="White" AllowSorting="True"
                                                        AutoGenerateColumns="true" Skin="MyCustomSkin" EnableEmbeddedSkins="false" ShowGroupPanel="True"
                                                        AllowMultiRowSelection="true" OnNeedDataSource="rdgImpactTimeList_NeedDataSource"
                                                        OnDeleteCommand="rdgImpactTimeList_DeleteCommand"
                                                        OnItemCommand="rdgImpactTimeList_ItemCommand" 
                                                     OnItemCreated="rdgImpactTimeList_ItemCreated"
                                                        OnLoad="rdgImpactTimeList_Load" 
                                                        Width="99.8%" Height="500px" PageSize="10"  EnableHeaderContextMenu="true">
                                                        <PagerStyle Mode="NextPrevAndNumeric" PrevPageToolTip="Previous" NextPagesToolTip="Next"
                                                            AlwaysVisible="true" />
                                                        <GroupingSettings CaseSensitive="false" ShowUnGroupButton="true" UnGroupButtonTooltip="Click here to ungroup" />
                                                        <MasterTableView Name="ImpactTimeList" ClientDataKeyNames="ImpactTimeID" DataKeyNames="ImpactTimeID" CommandItemDisplay="Top" AllowMultiColumnSorting="true"
                                                            Width="100%" ItemStyle-HorizontalAlign="Left" AlternatingItemStyle-HorizontalAlign="Left">
                                                            <FilterItemStyle HorizontalAlign="Left" />
                                                            <ItemStyle HorizontalAlign="Left" Height="10px"></ItemStyle>
                                                            <AlternatingItemStyle HorizontalAlign="Left"></AlternatingItemStyle>
                                                            <Columns>
                                                                <telerik:GridClientSelectColumn UniqueName="CheckboxSelectColumn" ItemStyle-HorizontalAlign="Left">
                                                                    <HeaderStyle Width="40px" />
                                                                </telerik:GridClientSelectColumn>
                                                                <telerik:GridEditCommandColumn EditImageUrl="~/images/telerik/Edit.gif" ButtonType="ImageButton"
                                                                    UniqueName="EditCommandColumn" ItemStyle-HorizontalAlign="Center">
                                                                    <HeaderStyle Width="40px" />
                                                                </telerik:GridEditCommandColumn>
                                                            </Columns>
                                                            <CommandItemTemplate>
                                                                <div style="padding: 5px 5px; text-align: left;">
                                                                    <span style="float: left;"><span id="spanAdd" runat="server" style="margin-left: 5px;
                                                                        margin-top: 5px; margin-bottom: 5px; margin-right: 10px;">
                                                                        <asp:LinkButton ID="btnInitInsert" runat="server" 
                                                                            CommandName="Add">
                                                                            <img id="imgAdd" runat="server" style="border: 0px; vertical-align: top;" alt=""
                                                                                src="~/images/telerik/AddRecord.png" />
                                                                            Add new
                                                                            </asp:LinkButton>
                                                                    </span><span style="margin-left: 5px; margin-top: 5px; margin-bottom: 5px; margin-right: 10px;">
                                                                        <asp:LinkButton ID="ToggleFiltering" runat="server" CausesValidation="false" CommandName="ToggleFiltering">
                                                                            <img id="imgToggle" runat="server" style="border: 0px; vertical-align: top;" alt=""
                                                                                src="~/images/telerik/search.png" />
                                                                            Filter</asp:LinkButton>
                                                                    </span><span style="margin-left: 5px; margin-top: 5px; margin-bottom: 5px; margin-right: 10px;">
                                                                        <asp:LinkButton ID="RemoveFilter" runat="server"  CausesValidation="false" CommandName="RemoveFilter">
                                                                            <img id="img1" runat="server" style="border: 0px; vertical-align: top;" alt="" src="~/images/telerik/filterdelete.png" />
                                                                            Remove Filter</asp:LinkButton>
                                                                    </span><span style="margin-left: 5px; margin-top: 5px; margin-bottom: 5px; margin-right: 10px;">
                                                                        <asp:LinkButton ID="btnRefresh" runat="server" CommandName="RebindGrid" CausesValidation="false">
                                                                            <img id="imgRefresh" runat="server" style="border: 0px; vertical-align: top;" alt=""
                                                                                src="~/images/telerik/Refresh.png" />
                                                                            Refresh</asp:LinkButton>
                                                                    </span></span>
                                                                </div>
                                                            </CommandItemTemplate>
                                                            <RowIndicatorColumn Visible="True">
                                                            </RowIndicatorColumn>
                                                        </MasterTableView>
                                                        <ClientSettings ColumnsReorderMethod="Reorder" AllowColumnsReorder="True" AllowKeyboardNavigation="true"
                                                            AllowAutoScrollOnDragDrop="true" ReorderColumnsOnClient="true" AllowDragToGroup="True"
                                                            EnableRowHoverStyle="true">
                                                            <Selecting AllowRowSelect="True" />
                                                            <ClientMessages DragToGroupOrReorder="Select All" />
                                                            <Selecting AllowRowSelect="True" />
                                                            <Resizing AllowColumnResize="true" EnableRealTimeResize="true" AllowRowResize="true"
                                                                ResizeGridOnColumnResize="true" ShowRowIndicatorColumn="false" />
                                                            <Scrolling AllowScroll="true" SaveScrollPosition="true" UseStaticHeaders="true">
                                                            </Scrolling>
                                                            <ClientEvents OnRowCreated="rdgImpactTimeList_RowCreated" OnRowSelected="rdgImpactTimeList_RowSelected"
                                                                OnRowDeselected="rdgImpactTimeList_RowDeselected" />
                                                        </ClientSettings>
                                                        <FilterMenu EnableEmbeddedSkins="false">
                                                        </FilterMenu>
                                                    </telerik:RadGrid>

Please help me get the add working.

2 Answers, 1 is accepted

Sort by
0
Bhavana
Top achievements
Rank 1
answered on 24 Nov 2013, 05:11 PM
Can someone help me with this issue...
0
Princy
Top achievements
Rank 2
answered on 25 Nov 2013, 04:01 AM
Hi Bhavana,

When firing custom commands they are fired through the first data item in the GridTableView. This means that no command will be fired if the grid is bound to an empty data source. You can try setting the CommandName="InitInsert" to make the grid open for insert. Please try and let me know if any concern.

Thanks,
Princy

Tags
Grid
Asked by
Bhavana
Top achievements
Rank 1
Answers by
Bhavana
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or